-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathide.html
More file actions
3296 lines (3074 loc) · 153 KB
/
ide.html
File metadata and controls
3296 lines (3074 loc) · 153 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">
<title>CommandGraph IDE</title>
<style>
:root {
--bg: #0e1117; --bg2: #161b22; --bg3: #1c2129; --bg-hover: #21262d;
--border: #30363d; --border-hi: #484f58;
--text: #e6edf3; --text2: #8b949e; --text3: #6e7681;
--accent: #58a6ff; --green: #3fb950; --amber: #d29922;
--red: #f85149; --purple: #bc8cff; --coral: #f0883e;
--teal: #39d353; --pink: #f778ba;
--mono: "SF Mono","Cascadia Code","Fira Code","JetBrains Mono","Consolas",monospace;
--sans: "Segoe UI",system-ui,-apple-system,sans-serif;
--radius: 6px;
}
@media (prefers-color-scheme:light) {
:root:not(.dark) {
--bg: #f6f8fa; --bg2: #ffffff; --bg3: #f0f2f5; --bg-hover: #eaeef2;
--border: #d0d7de; --border-hi: #afb8c1;
--text: #1f2328; --text2: #656d76; --text3: #8c959f;
--accent: #0969da; --green: #1a7f37; --amber: #9a6700;
--red: #cf222e; --purple: #8250df; --coral: #bc4c00;
--teal: #0f6e56; --pink: #bf3989;
}
}
:root.light {
--bg: #f6f8fa; --bg2: #ffffff; --bg3: #f0f2f5; --bg-hover: #eaeef2;
--border: #d0d7de; --border-hi: #afb8c1;
--text: #1f2328; --text2: #656d76; --text3: #8c959f;
--accent: #0969da; --green: #1a7f37; --amber: #9a6700;
--red: #cf222e; --purple: #8250df; --coral: #bc4c00;
--teal: #0f6e56; --pink: #bf3989;
}
* { margin:0; padding:0; box-sizing:border-box; }
body { background:var(--bg); color:var(--text); font-family:var(--sans); height:100vh; overflow:hidden; }
/* Header */
.hdr { background:var(--bg2); border-bottom:1px solid var(--border); padding:8px 14px; display:flex; align-items:center; gap:12px; height:42px; z-index:100; }
.hdr h1 { font-family:var(--mono); font-size:13px; font-weight:600; color:var(--accent); }
.hdr .sep { color:var(--text3); }
.hdr .fname { font-family:var(--mono); font-size:12px; color:var(--text); cursor:pointer; }
.hdr .fname:hover { color:var(--accent); }
.hdr .dirty { color:var(--amber); font-size:10px; }
.hdr .actions { margin-left:auto; display:flex; gap:6px; align-items:center; }
.btn { background:var(--bg3); border:1px solid var(--border); border-radius:var(--radius); color:var(--text2); font-size:11px; padding:4px 10px; cursor:pointer; font-family:var(--mono); transition:all .15s; }
.btn:hover { background:var(--bg-hover); color:var(--text); border-color:var(--border-hi); }
.btn-primary { background:var(--accent); color:#fff; border-color:var(--accent); }
.btn-primary:hover { opacity:.85; }
.btn-green { background:var(--green); color:#fff; border-color:var(--green); }
.btn-green:hover { opacity:.85; }
.status { font-size:11px; font-family:var(--mono); padding:2px 8px; border-radius:10px; }
.status-ok { background:rgba(63,185,80,.12); color:var(--green); }
.status-err { background:rgba(248,81,73,.12); color:var(--red); }
.status-info { background:rgba(88,166,255,.1); color:var(--accent); }
.status-warn { background:rgba(210,153,34,.12); color:var(--amber); }
.problems-panel { padding:0; font-size:12px; max-height:180px; overflow-y:auto; border-top:1px solid var(--border); background:var(--bg); }
.problems-panel.show { display:block; }
.prob-item { padding:4px 12px; display:flex; gap:6px; align-items:baseline; cursor:pointer; font-family:var(--mono); font-size:11px; }
.prob-item:hover { background:var(--bg-hover); }
.prob-icon { flex-shrink:0; width:14px; text-align:center; }
.prob-icon.prob-err { color:var(--red); }
.prob-icon.prob-warn { color:var(--amber); }
.prob-icon.prob-info { color:var(--text3); }
.prob-msg { color:var(--text2); flex:1; }
.prob-loc { color:var(--text3); font-size:10px; white-space:nowrap; }
.prob-file-link { color:var(--accent); text-decoration:underline; cursor:pointer; }
.prob-file-link:hover { color:var(--text); }
.prob-summary { padding:4px 12px; font-size:10px; font-family:var(--mono); color:var(--text3); border-bottom:1px solid var(--border); display:flex; justify-content:space-between; align-items:center; }
.prob-summary .prob-close { cursor:pointer; color:var(--text3); padding:0 4px; }
.prob-summary .prob-close:hover { color:var(--text); }
/* Main layout */
.main { display:flex; flex-direction:column; height:calc(100vh - 42px); }
.main-panels { display:flex; flex:1; overflow:hidden; }
/* Editor panel */
.editor-panel { width:40%; min-width:300px; display:flex; flex-direction:column; border-right:1px solid var(--border); }
.editor-tabs { display:flex; gap:0; background:var(--bg2); border-bottom:1px solid var(--border); padding:0 8px; }
.tab { padding:6px 12px; font-size:11px; font-family:var(--mono); color:var(--text3); cursor:pointer; border-bottom:2px solid transparent; transition:all .15s; }
.tab:hover { color:var(--text2); }
.tab.active { color:var(--accent); border-bottom-color:var(--accent); }
.editor-wrap { flex:1; position:relative; overflow:hidden; }
.editor-container { display:flex; height:100%; overflow:auto; background:var(--bg); }
.line-numbers { padding:10px 0; text-align:right; min-width:40px; padding-right:10px; font-family:var(--mono); font-size:13px; line-height:1.6; color:var(--text3); user-select:none; background:var(--bg2); border-right:1px solid var(--border); flex-shrink:0; }
.editor-area { position:relative; flex:1; min-height:100%; }
.highlight-layer { padding:10px 12px; font-family:var(--mono); font-size:13px; line-height:1.6; white-space:pre-wrap; word-wrap:break-word; pointer-events:none; user-select:none; -webkit-user-select:none; color:var(--text); width:100%; min-height:100%; }
textarea#code { position:absolute; top:0; left:0; width:100%; height:100%; padding:10px 12px; font-family:var(--mono); font-size:13px; line-height:1.6; background:transparent; color:var(--text); border:none; outline:none; resize:none; white-space:pre-wrap; word-wrap:break-word; caret-color:var(--text); -webkit-text-fill-color:transparent; overflow:hidden; }
/* Syntax highlighting */
.hl-kw { color:var(--accent); font-weight:600; }
.hl-str { color:var(--green); }
.hl-step { color:var(--coral); font-weight:600; }
.hl-cmd { color:var(--text); }
.hl-comment { color:var(--text3); font-style:italic; }
.hl-var { color:var(--purple); }
.hl-prop { color:var(--amber); }
.hl-title { color:var(--pink); font-weight:700; }
.hl-upath { color:var(--accent); text-decoration:underline; text-decoration-style:dotted; text-underline-offset:2px; }
/* Error gutter */
.line-numbers .ln-err { color:var(--red); font-weight:700; }
/* Graph + Log area */
.graph-log-area { flex:1; display:flex; flex-direction:column; overflow:hidden; }
/* Graph tab bar */
.graph-tabs { display:flex; gap:0; background:var(--bg2); border-bottom:1px solid var(--border); padding:0 8px; flex-shrink:0; }
.gtab { padding:5px 12px; font-size:11px; font-family:var(--mono); color:var(--text3); cursor:pointer; border-bottom:2px solid transparent; transition:all .15s; display:flex; align-items:center; gap:5px; }
.gtab:hover { color:var(--text2); }
.gtab.active { color:var(--accent); border-bottom-color:var(--accent); }
.gtab-close { font-size:14px; color:var(--text3); margin-left:2px; line-height:1; }
.gtab-close:hover { color:var(--red); }
/* File viewer panel (replaces graph) */
.fileview-panel { flex:1; display:flex; flex-direction:column; overflow:hidden; }
.fileview-hdr { display:flex; align-items:center; gap:8px; padding:6px 12px; background:var(--bg2); border-bottom:1px solid var(--border); flex-shrink:0; }
.fileview-lock { font-size:12px; }
.fileview-path { font-family:var(--mono); font-size:11px; color:var(--text2); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.fileview-msg { font-family:var(--mono); font-size:10px; color:var(--text3); }
.fileview-body { flex:1; overflow:auto; background:var(--bg); }
.fileview-editor-wrap { display:flex; min-height:100%; }
.fv-line-numbers { padding:10px 0; text-align:right; min-width:40px; padding-right:10px; font-family:var(--mono); font-size:13px; line-height:1.6; color:var(--text3); user-select:none; background:var(--bg2); border-right:1px solid var(--border); flex-shrink:0; }
.fv-editor-area { position:relative; flex:1; min-height:100%; }
.fv-highlight { padding:10px 12px; font-family:var(--mono); font-size:13px; line-height:1.6; white-space:pre-wrap; word-wrap:break-word; pointer-events:none; user-select:none; color:var(--text); width:100%; min-height:100%; }
.fv-textarea { position:absolute; top:0; left:0; width:100%; height:100%; padding:10px 12px; font-family:var(--mono); font-size:13px; line-height:1.6; background:transparent; color:var(--text); border:none; outline:none; resize:none; white-space:pre-wrap; word-wrap:break-word; caret-color:var(--text); -webkit-text-fill-color:transparent; overflow:hidden; }
.fv-textarea[readonly] { cursor:default; }
.graph-panel { flex:1; overflow:auto; position:relative; padding:16px; }
.graph-panel .empty-msg { color:var(--text3); font-size:13px; text-align:center; padding:60px 20px; }
/* Log resize handle */
.log-resize { height:4px; background:var(--border); cursor:ns-resize; flex-shrink:0; }
.log-resize:hover { background:var(--accent); }
/* Log pane */
.log-pane { height:220px; min-height:80px; max-height:60vh; display:flex; flex-direction:column; border-top:1px solid var(--border); background:var(--bg); flex-shrink:0; }
.log-pane.collapsed { height:auto; min-height:0; max-height:none; }
.log-pane.collapsed .log-body { display:none; }
.log-pane.collapsed .log-header { border-bottom:none; }
.log-header { display:flex; align-items:center; gap:8px; padding:4px 10px; background:var(--bg2); border-bottom:1px solid var(--border); flex-shrink:0; cursor:pointer; }
.log-title { font-family:var(--mono); font-size:13px; font-weight:600; color:var(--text2); }
.log-actions { margin-left:auto; display:flex; gap:4px; }
.log-btn { padding:2px 7px; font-size:11px; }
.log-follow { display:flex; align-items:center; gap:3px; font-family:var(--mono); font-size:10px; color:var(--text3); cursor:pointer; padding:0 6px; user-select:none; }
.log-follow input { cursor:pointer; accent-color:var(--accent); }
.log-body { flex:1; overflow:auto; padding:6px 10px; font-family:var(--mono); font-size:13px; line-height:1.6; }
/* Log entry highlight flash when scrolled to */
@keyframes log-flash { 0%{background:rgba(88,166,255,.2)} 100%{background:transparent} }
.log-entry.flash { animation:log-flash 1.2s ease-out; }
/* Log entries */
.log-entry { border-bottom:1px solid var(--border); padding:4px 0; }
.log-entry:last-child { border-bottom:none; }
.log-entry-hdr { display:flex; align-items:center; gap:6px; cursor:pointer; padding:2px 0; border-radius:var(--radius); }
.log-entry-hdr:hover { background:var(--bg-hover); }
.log-icon { width:16px; text-align:center; flex-shrink:0; }
.log-icon.ok { color:var(--green); }
.log-icon.skip { color:var(--text3); }
.log-icon.fail { color:var(--red); }
.log-icon.warn { color:var(--amber); }
.log-name { flex:1; color:var(--text); }
.log-desc { color:var(--text3); font-size:11px; margin-left:4px; }
.log-time { color:var(--text3); font-size:11px; flex-shrink:0; }
.log-rc { font-size:11px; padding:0 5px; border-radius:6px; flex-shrink:0; }
.log-rc.rc-ok { background:rgba(63,185,80,.12); color:var(--green); }
.log-rc.rc-fail { background:rgba(248,81,73,.12); color:var(--red); }
.log-detail { display:none; padding:4px 0 4px 22px; }
.log-detail.open { display:block; }
.log-detail-section { margin:3px 0; }
.log-detail-label { color:var(--text3); font-size:10px; text-transform:uppercase; letter-spacing:.5px; }
.log-detail-cmd { background:var(--bg3); border:1px solid var(--border); border-radius:var(--radius); padding:5px 9px; font-size:12px; margin:2px 0; white-space:pre-wrap; word-break:break-all; color:var(--text); max-height:140px; overflow:auto; }
.log-detail-cmd.cmd-stdout { color:var(--text2); }
.log-detail-cmd.cmd-stderr { color:var(--red); border-color:rgba(248,81,73,.3); }
.log-wave-hdr { color:var(--text3); font-size:12px; font-weight:700; letter-spacing:.3px; padding:6px 0 2px; border-bottom:1px solid var(--border); margin:4px 0 2px; }
.log-summary { padding:8px 0; font-weight:700; font-size:14px; }
.log-summary.ok { color:var(--green); }
.log-summary.fail { color:var(--red); }
/* Reuse existing viz styles */
.wc { margin:0 0 3px; }
.wl { font-family:var(--mono); font-size:11px; color:var(--text3); font-weight:700; letter-spacing:.3px; padding:0 0 5px; display:flex; align-items:center; gap:7px; flex-wrap:wrap; }
.wl::after { content:""; flex:1; height:1px; background:var(--border); min-width:20px; }
.wl-count { font-weight:400; color:var(--text3); }
.wl-summary { font-weight:400; font-size:11px; color:var(--text2); letter-spacing:0; max-width:500px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.wl-phase { background:rgba(88,166,255,.12); color:var(--accent); font-size:9px; padding:0 6px; border-radius:8px; font-weight:700; text-transform:uppercase; letter-spacing:.5px; }
.wr { display:flex; flex-wrap:wrap; gap:6px; padding:6px 0 6px 14px; border-left:2px solid var(--border); margin-left:3px; }
.nc { background:var(--bg2); border:1px solid var(--border); border-radius:var(--radius); padding:8px 10px 8px 10px; cursor:pointer; transition:all .15s; position:relative; max-width:240px; min-width:110px; }
.nc:hover { border-color:var(--border-hi); background:var(--bg-hover); transform:translateY(-1px); }
.nc.sel { border-color:var(--accent); box-shadow:0 0 0 1px var(--accent); }
.nc.dep { border-color:var(--green); background:rgba(63,185,80,.06); }
.nc.depnt { border-color:var(--purple); background:rgba(188,140,255,.06); }
.nc.cdim { opacity:.2; }
.nc.editor-hl { border-color:var(--accent); background:rgba(88,166,255,.1); box-shadow:0 0 0 1px rgba(88,166,255,.3); }
.nc.follow-hl { border-color:var(--amber); box-shadow:0 0 0 2px rgba(210,153,34,.4); animation:demo-pulse .8s ease-in-out infinite; }
.nc.diff-added { border-color:var(--green); box-shadow:0 0 0 2px rgba(63,185,80,.3); }
.nc.diff-added::after { content:'NEW'; position:absolute; top:2px; right:4px; font-size:8px; color:var(--green); font-weight:700; }
.nc.diff-changed { border-color:var(--amber); box-shadow:0 0 0 2px rgba(210,153,34,.25); }
.nc.diff-changed::after { content:'CHANGED'; position:absolute; top:2px; right:4px; font-size:8px; color:var(--amber); font-weight:700; }
/* SVG dependency arrows */
.sa { position:absolute; top:0; left:0; pointer-events:none; z-index:1; }
.ap { fill:none; stroke:var(--border-hi); stroke-width:1; opacity:.3; transition:opacity .2s, stroke .2s; }
.ap.hd { stroke:var(--green); opacity:.7; stroke-width:1.5; }
.ap.ht { stroke:var(--purple); opacity:.7; stroke-width:1.5; }
/* Editor line highlight strip */
.line-numbers .ln-hl { background:rgba(88,166,255,.15); }
.editor-line-hl { position:absolute; left:0; width:100%; height:1.6em; background:rgba(88,166,255,.08); pointer-events:none; z-index:0; transition:top .1s ease-out; }
.nn { font-family:var(--mono); font-size:13px; font-weight:600; color:var(--text); margin:0 0 2px; padding-right:40px; }
.nd { font-size:11px; color:var(--text2); line-height:1.4; overflow:hidden; text-overflow:ellipsis; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; }
.nb { display:flex; gap:3px; margin-top:4px; flex-wrap:wrap; }
.bg { font-size:10px; padding:1px 6px; border-radius:7px; font-family:var(--mono); font-weight:600; line-height:1.7; }
.bg-p { background:rgba(88,166,255,.12); color:var(--accent); }
.bg-v { background:rgba(247,120,186,.12); color:var(--pink); }
.bg-r { background:rgba(210,153,34,.12); color:var(--amber); }
.nc.barrier { opacity:.4; border-style:dashed; min-width:60px; max-width:110px; }
.nc.barrier .nn { font-size:9px; color:var(--text3); }
.grp { border:1px dashed var(--border-hi); border-radius:8px; padding:8px 8px 6px; margin:2px 0; }
.grp-par { border-color:var(--accent); }
.grp-race { border-color:var(--coral); }
.grp-each { border-color:var(--teal); }
.grp-phase { border-color:var(--purple); }
.grp-lbl { font-family:var(--mono); font-size:9px; font-weight:700; text-transform:uppercase; padding:0 5px; margin:0 0 5px; }
.grp-par .grp-lbl { color:var(--accent); }
.grp-race .grp-lbl { color:var(--coral); }
.grp-each .grp-lbl { color:var(--teal); }
.grp-phase .grp-lbl { color:var(--purple); }
.grp-cards { display:flex; flex-wrap:wrap; gap:6px; }
.nc.st-success { border-left:3px solid var(--green); }
.nc.st-failed { border-left:3px solid var(--red); background:rgba(248,81,73,.05); }
.nc.st-warned { border-left:3px solid var(--amber); }
/* Node groups within waves */
.ng { border:1px solid var(--border); border-radius:6px; margin:2px 0; overflow:hidden; width:100%; }
.ng-hdr { display:flex; align-items:center; gap:8px; padding:5px 10px; cursor:pointer; font-family:var(--mono); font-size:11px; background:var(--bg2); user-select:none; }
.ng-hdr:hover { background:var(--bg-hover); }
.ng-toggle { color:var(--text3); font-size:9px; flex-shrink:0; width:12px; text-align:center; }
.ng-name { font-weight:700; color:var(--text); }
.ng-via { color:var(--text3); font-size:10px; }
.ng-count { color:var(--text2); margin-left:auto; font-size:10px; }
.ng-state { display:flex; gap:6px; font-size:10px; }
.ng-state .ns-ok { color:var(--green); }
.ng-state .ns-fail { color:var(--red); }
.ng-state .ns-pend { color:var(--text3); }
.ng-body { display:flex; flex-wrap:wrap; gap:6px; padding:6px 10px; }
.ng.collapsed .ng-body { display:none; }
.ng.collapsed { border-color:var(--border); }
/* Info bar */
.info-bar { background:var(--bg2); border-top:1px solid var(--border); padding:6px 14px; font-family:var(--mono); font-size:11px; color:var(--text2); display:flex; gap:14px; flex-wrap:wrap; }
.info-bar .st { display:flex; align-items:center; gap:3px; }
.info-bar .stn { color:var(--text); font-weight:600; }
/* Inspector panel */
.inspector { width:280px; min-width:250px; background:var(--bg2); border-left:1px solid var(--border); overflow-y:auto; padding:14px; }
.inspector h2 { font-family:var(--mono); font-size:13px; font-weight:600; color:var(--accent); margin:0 0 10px; word-break:break-all; }
.inspector .empty { color:var(--text3); font-size:12px; font-style:italic; padding:28px 0; text-align:center; }
.ds { margin:0 0 12px; }
.ds h3 { font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:.5px; color:var(--text3); margin:0 0 4px; }
.dcmd { background:var(--bg3); border:1px solid var(--border); border-radius:var(--radius); padding:6px 8px; font-family:var(--mono); font-size:11px; color:var(--text); white-space:pre-wrap; word-break:break-all; margin:3px 0; }
.dbadge { display:inline-block; padding:1px 6px; border-radius:9px; font-size:10px; font-weight:600; font-family:var(--mono); }
.ddeps { display:flex; flex-wrap:wrap; gap:3px; margin:3px 0; }
.dchip { background:var(--bg3); border:1px solid var(--border); border-radius:var(--radius); padding:1px 6px; font-size:10px; font-family:var(--mono); color:var(--text2); cursor:pointer; transition:all .15s; }
.dchip:hover { border-color:var(--accent); color:var(--accent); }
/* Resize handle */
.resize-handle { width:4px; cursor:col-resize; background:transparent; transition:background .2s; flex-shrink:0; }
.resize-handle:hover, .resize-handle.active { background:var(--accent); }
/* Autocomplete popup */
.ac-popup { display:none; position:absolute; z-index:200; background:var(--bg2); border:1px solid var(--border); border-radius:var(--radius); max-height:160px; overflow-y:auto; min-width:180px; box-shadow:0 4px 12px rgba(0,0,0,.3); }
.ac-popup.show { display:block; }
.ac-item { padding:4px 10px; font-family:var(--mono); font-size:11px; color:var(--text2); cursor:pointer; display:flex; align-items:center; gap:6px; }
.ac-item:hover, .ac-item.sel { background:var(--accent); color:#fff; }
.ac-icon { font-size:9px; opacity:.6; }
/* Inspector tabs */
.insp-tabs { display:flex; gap:0; border-bottom:1px solid var(--border); margin:0 -14px 10px; padding:0 14px; }
.insp-tabs .tab { padding:5px 10px; font-size:11px; font-family:var(--mono); color:var(--text3); cursor:pointer; border-bottom:2px solid transparent; }
.insp-tabs .tab:hover { color:var(--text2); }
.insp-tabs .tab.active { color:var(--accent); border-bottom-color:var(--accent); }
/* Execution log */
.exec-log { font-family:var(--mono); font-size:11px; line-height:1.7; }
.exec-log .ev { padding:2px 0; display:flex; align-items:flex-start; gap:6px; }
.exec-log .ev-wave { color:var(--text3); font-weight:700; font-size:10px; letter-spacing:.3px; margin:6px 0 2px; border-bottom:1px solid var(--border); padding-bottom:2px; }
.exec-log .ev-ok { color:var(--green); }
.exec-log .ev-skip { color:var(--text3); }
.exec-log .ev-fail { color:var(--red); }
.exec-log .ev-warn { color:var(--amber); }
.exec-log .ev-icon { flex-shrink:0; width:14px; text-align:center; }
.exec-log .ev-name { flex:1; }
.exec-log .ev-time { color:var(--text3); font-size:10px; }
.exec-log .ev-err { color:var(--red); font-size:10px; padding:2px 0 2px 20px; word-break:break-all; }
.exec-log .ev-done { padding:8px 0; font-weight:700; }
.exec-log .ev-done.ok { color:var(--green); }
.exec-log .ev-done.fail { color:var(--red); }
.exec-log .ev-rerun { font-size:10px; color:var(--accent); cursor:pointer; text-decoration:underline; margin-left:4px; }
.exec-log .ev-rerun:hover { color:var(--text); }
.exec-log .ev-running { color:var(--amber); }
.exec-log .ev-block { padding:2px 0 4px; border-bottom:1px solid var(--border); }
.exec-log .ev-block:last-child { border-bottom:none; }
.exec-log .ev-stream { margin:2px 0 0 20px; padding:4px 7px; background:var(--bg3); border:1px solid var(--border); border-radius:var(--radius); white-space:pre-wrap; word-break:break-all; max-height:140px; overflow:auto; font-size:10px; }
.exec-log .ev-stream:empty { display:none; }
.exec-log .ev-stream.stdout { color:var(--text2); }
.exec-log .ev-stream.stderr { color:var(--red); border-color:rgba(248,81,73,.3); }
.exec-log .ev-meta { margin:2px 0 0 20px; color:var(--text3); font-size:10px; white-space:pre-wrap; }
.exec-log .ev-meta.waiting { color:var(--amber); }
.exec-log .ev-cmd { margin:2px 0 0 20px; padding:4px 7px; background:var(--bg3); border:1px solid var(--border); border-radius:var(--radius); white-space:pre-wrap; word-break:break-all; max-height:120px; overflow:auto; font-size:10px; color:var(--text); }
.exec-input { display:none; gap:8px; align-items:center; padding:8px 0 0; }
.exec-input.show { display:flex; }
.exec-input-label { color:var(--text3); font-size:10px; font-family:var(--mono); text-transform:uppercase; letter-spacing:.5px; }
.exec-input-box { flex:1; min-width:0; background:var(--bg3); color:var(--text); border:1px solid var(--border); border-radius:var(--radius); padding:7px 9px; font-family:var(--mono); font-size:12px; }
.exec-input-box:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 1px rgba(88,166,255,.2); }
.exec-input-send { white-space:nowrap; }
.exec-input-toggle { white-space:nowrap; }
.log-entry.running .log-icon { color:var(--amber); }
.term-fg-black { color:#484f58; }
.term-fg-red { color:#ff7b72; }
.term-fg-green { color:#7ee787; }
.term-fg-yellow { color:#e3b341; }
.term-fg-blue { color:#79c0ff; }
.term-fg-magenta { color:#d2a8ff; }
.term-fg-cyan { color:#56d4dd; }
.term-fg-white { color:#f0f6fc; }
.term-bold { font-weight:700; }
/* Graph toolbar */
.graph-toolbar { display:flex; gap:6px; align-items:center; margin:0 0 10px; }
/* State badges on cards */
.stb { position:absolute; top:4px; right:4px; font-size:10px; font-weight:700; font-family:var(--mono); padding:0 5px; border-radius:4px; line-height:1.6; }
.stb-success { background:rgba(63,185,80,.15); color:var(--green); }
.stb-skip { background:rgba(63,185,80,.1); color:var(--green); }
.stb-failed { background:rgba(248,81,73,.15); color:var(--red); }
.stb-checking { background:rgba(88,166,255,.15); color:var(--accent); }
.stb-running { background:rgba(210,153,34,.15); color:var(--amber); }
.stb-resuming { background:rgba(188,140,255,.15); color:var(--purple); }
/* Demo animations */
@keyframes demo-pulse { 0%,100%{opacity:1} 50%{opacity:.6} }
@keyframes demo-shake { 0%,100%{transform:translateX(0)} 15%{transform:translateX(-3px)} 30%{transform:translateX(3px)} 45%{transform:translateX(-2px)} 60%{transform:translateX(2px)} 75%{transform:translateX(-1px)} }
.nc.demo-checking { border-left:3px solid var(--accent); animation:demo-pulse .8s ease-in-out infinite; }
.nc.demo-running { border-left:3px solid var(--amber); animation:demo-pulse .8s ease-in-out infinite; }
.nc.demo-failed-shake { animation:demo-shake .4s ease-in-out; }
.nc.demo-resuming { border-left:3px solid var(--purple); animation:demo-pulse .6s ease-in-out infinite; }
.nc.st-success { border-left:3px solid var(--green); }
.nc.st-skip_check { border-left:3px solid var(--green); opacity:.7; }
.nc.st-failed { border-left:3px solid var(--red); background:rgba(248,81,73,.05); }
/* More menu */
.more-menu.show { display:block !important; }
.more-item { padding:5px 10px; font-family:var(--mono); font-size:11px; color:var(--text2); cursor:pointer; }
.more-item:hover { background:var(--bg-hover); color:var(--text); }
/* Demo button states */
#bdemo.demo-active { color:var(--amber); font-weight:700; }
#bdemo.demo-done { color:var(--text3); }
/* Wave progress */
.wl .wprog { display:inline-block; margin-left:8px; font-size:10px; color:var(--text3); font-family:var(--mono); }
.wprog-bar { display:inline-block; width:60px; height:5px; background:var(--bg3); border-radius:3px; vertical-align:middle; margin-right:4px; overflow:hidden; }
.wprog-fill { height:100%; background:var(--green); border-radius:3px; transition:width .3s ease-out; }
/* Toast */
.toast { background:var(--bg2); border:1px solid var(--border); border-radius:var(--radius); padding:6px 12px; font-size:11px; font-family:var(--mono); color:var(--text); box-shadow:0 4px 12px rgba(0,0,0,.3); animation:toast-in .3s ease-out; max-width:320px; }
.toast.toast-fail { border-color:var(--red); background:rgba(248,81,73,.08); }
.toast.toast-resume { border-color:var(--purple); background:rgba(188,140,255,.08); }
.toast.toast-done { border-color:var(--green); background:rgba(63,185,80,.08); }
@keyframes toast-in { from{opacity:0;transform:translateY(-10px)} to{opacity:1;transform:translateY(0)} }
.file-picker-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.45); display:none; align-items:flex-start; justify-content:center; padding-top:72px; z-index:250; }
.file-picker { width:min(680px, calc(100vw - 40px)); max-height:min(70vh, 720px); background:var(--bg2); border:1px solid var(--border-hi); border-radius:10px; box-shadow:0 18px 60px rgba(0,0,0,.45); display:flex; flex-direction:column; overflow:hidden; }
.file-picker-hdr { display:flex; align-items:center; gap:8px; padding:10px 12px; border-bottom:1px solid var(--border); font-family:var(--mono); font-size:12px; color:var(--text2); }
.file-picker-search { margin:12px; margin-bottom:8px; width:calc(100% - 24px); background:var(--bg3); border:1px solid var(--border); border-radius:var(--radius); color:var(--text); font-family:var(--mono); font-size:12px; padding:8px 10px; outline:none; }
.file-picker-search:focus { border-color:var(--accent); box-shadow:0 0 0 1px var(--accent); }
.file-picker-controls { display:flex; align-items:center; gap:10px; padding:0 12px 10px; }
.file-picker-filter { display:flex; align-items:center; gap:8px; font-family:var(--mono); font-size:11px; color:var(--text3); }
.file-picker-filter select { background:var(--bg3); border:1px solid var(--border); border-radius:var(--radius); color:var(--text); font-family:var(--mono); font-size:11px; padding:6px 8px; outline:none; }
.file-picker-filter select:focus { border-color:var(--accent); box-shadow:0 0 0 1px var(--accent); }
.file-picker-list { padding:0 12px 12px; overflow:auto; }
.file-picker-item { padding:8px 10px; margin:0 0 6px; border:1px solid var(--border); border-radius:var(--radius); background:var(--bg3); cursor:pointer; transition:all .15s; }
.file-picker-item:hover { border-color:var(--accent); background:var(--bg-hover); }
.file-picker-item.active { border-color:var(--accent); box-shadow:0 0 0 1px rgba(88,166,255,.35); }
.file-picker-path { font-family:var(--mono); font-size:12px; color:var(--text); display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.file-picker-meta { margin-top:2px; font-size:10px; color:var(--text3); }
.file-picker-tag { display:inline-block; padding:1px 6px; border-radius:999px; font-size:9px; font-weight:700; letter-spacing:.03em; text-transform:uppercase; }
.file-picker-tag.cgr { background:rgba(88,166,255,.14); color:var(--accent); }
.file-picker-tag.cg { background:rgba(210,153,34,.14); color:var(--amber); }
.file-picker-tag.root { background:rgba(139,148,158,.18); color:var(--text2); }
.file-picker-tag.example { background:rgba(63,185,80,.14); color:var(--green); }
.file-picker-tag.testing { background:rgba(188,140,255,.14); color:var(--purple); }
.file-picker-tag.template { background:rgba(240,136,62,.15); color:var(--coral); }
.file-picker-empty { padding:14px 6px; color:var(--text3); font-size:12px; text-align:center; }
.file-picker-trigger { display:inline-flex; align-items:center; justify-content:center; width:22px; height:22px; border:1px solid var(--border); border-radius:var(--radius); background:var(--bg3); color:var(--text2); cursor:pointer; font-size:12px; transition:all .15s; }
.file-picker-trigger:hover { border-color:var(--accent); color:var(--accent); background:var(--bg-hover); }
.file-picker-trigger.disabled { opacity:.45; cursor:default; }
</style>
</head>
<body>
<div class="hdr">
<h1>◇ CommandGraph</h1>
<span class="sep">|</span>
<span class="fname" id="filename" title="Click to change file">—</span>
<button class="file-picker-trigger" id="filePickerBtn" title="Open graph file (Ctrl+O)">📂</button>
<span class="dirty" id="dirty" style="display:none">● unsaved</span>
<div class="actions">
<span class="status status-info" id="statusBadge">loading...</span>
<button class="btn" onclick="doSave()" title="Ctrl+S">Save</button>
<button class="btn btn-primary" onclick="doCheck()" title="Ctrl+Shift+V" id="checkBtn">Check</button>
<button class="btn btn-green" id="applyBtn" onclick="doApply()" title="Ctrl+Enter">▶ Apply</button>
<button class="btn" id="rerunBtn" onclick="doApplyFresh()" title="Reset state and re-run all steps (Ctrl+Shift+Enter)">⟳ Re-run</button>
<button class="btn" id="themeBtn" onclick="toggleTheme()" title="Toggle dark/light mode" style="font-size:15px;padding:2px 8px"></button>
</div>
</div>
<div class="main">
<div class="main-panels">
<!-- Editor -->
<div class="editor-panel" id="editorPanel">
<div class="editor-wrap">
<div class="editor-container" id="editorContainer">
<div class="line-numbers" id="lineNumbers"></div>
<div class="editor-area" id="editorArea">
<div class="highlight-layer" id="highlight"></div>
<textarea id="code" spellcheck="false" autocomplete="off" autocapitalize="off"></textarea>
</div>
</div>
</div>
<div class="problems-panel" id="problemsPanel" style="display:none"></div>
</div>
<div class="resize-handle" id="resizeH"></div>
<!-- Graph + Log column -->
<div class="graph-log-area">
<!-- Tab bar for Graph / File view -->
<div class="graph-tabs" id="graphTabs">
<div class="gtab active" data-gtab="graph" onclick="switchGraphTab('graph')">Graph</div>
<div class="gtab" data-gtab="fileview" id="gtabFile" onclick="switchGraphTab('fileview')" style="display:none">
<span id="gtabFileIcon">📦</span>
<span id="gtabFileLabel"></span>
<span class="gtab-close" onclick="event.stopPropagation();closeSideEditor()" title="Close file">×</span>
</div>
</div>
<div class="graph-panel" id="graphPanel">
<div class="graph-toolbar" id="graphToolbar" style="display:none">
<button class="btn" id="bcollapse" onclick="toggleCollapseAll()" title="Collapse/expand node groups" style="display:none">▼ Collapse</button>
<button class="btn" id="bedges" onclick="cycleEdgeMode()" title="Cycle edge visibility: all / selection / off">⟋ Edges: all</button>
<div style="position:relative;display:inline-block">
<button class="btn" onclick="document.getElementById('moreMenu').classList.toggle('show')" title="More options">⋯</button>
<div id="moreMenu" class="more-menu" style="display:none;position:absolute;right:0;top:100%;z-index:50;background:var(--bg2);border:1px solid var(--border);border-radius:var(--radius);padding:4px 0;min-width:160px;box-shadow:0 4px 12px rgba(0,0,0,.3)">
<div class="more-item" onclick="demoToggle();document.getElementById('moreMenu').classList.remove('show')">
<span id="bdemo">▶ Demo</span>
</div>
<div class="more-item" style="padding:4px 10px;display:flex;align-items:center;gap:6px">
<span style="color:var(--text3);font-size:11px">Speed</span>
<select id="dspeed" onchange="demoSpeed(this.value)" style="background:var(--bg3);border:1px solid var(--border);border-radius:var(--radius);color:var(--text2);font-size:11px;padding:1px 4px;font-family:var(--mono);cursor:pointer;flex:1">
<option value="0.5">0.5x</option><option value="1" selected>1x</option><option value="2">2x</option><option value="4">4x</option>
</select>
</div>
</div>
</div>
</div>
<div class="empty-msg" id="emptyMsg">Edit a .cgr file to see the dependency graph</div>
<svg class="sa" id="svg"></svg>
<div id="waves"></div>
</div>
<!-- File viewer panel (shown in place of graph) -->
<div class="fileview-panel" id="fileviewPanel" style="display:none">
<div class="fileview-hdr">
<span class="fileview-lock" id="fvLock" title="Read-only">🔒</span>
<span class="fileview-path" id="fvPath"></span>
<span class="dbadge" id="fvBadge" style="font-size:9px"></span>
<div style="margin-left:auto;display:flex;gap:6px;align-items:center">
<span class="fileview-msg" id="fvMsg">Read-only</span>
<button class="btn" id="fvEditBtn" onclick="toggleSideEdit()" style="font-size:10px;padding:2px 8px">Enable editing</button>
</div>
</div>
<div class="fileview-body" id="fvBody">
<div class="fileview-editor-wrap">
<div class="fv-line-numbers" id="fvLineNumbers"></div>
<div class="fv-editor-area">
<div class="fv-highlight" id="fvHighlight"></div>
<textarea id="fvCode" class="fv-textarea" spellcheck="false" autocomplete="off" autocapitalize="off" readonly></textarea>
</div>
</div>
</div>
</div>
<div class="log-resize" id="logResizeH" style="display:none"></div>
<div class="log-pane collapsed" id="logPane" style="display:none">
<div class="log-header" onclick="toggleLogCollapse()">
<span class="log-title" id="logTitle">Execution log</span>
<div class="log-actions">
<label class="log-follow" onclick="event.stopPropagation()" title="Auto-scroll to current step during execution">
<input type="checkbox" id="logFollowCb" checked> Follow
</label>
<button class="btn log-btn" onclick="event.stopPropagation();toggleLogExpand()" id="logExpandBtn" title="Expand/collapse all entries">⊟ Collapse All</button>
<button class="btn log-btn" onclick="event.stopPropagation();clearLog()" title="Clear log">Clear</button>
<button class="btn log-btn" id="logCollapseBtn" onclick="event.stopPropagation();toggleLogCollapse()" title="Expand/collapse log">▲</button>
</div>
</div>
<div id="progressWrap" style="height:3px;background:var(--border);display:none"><div id="progressBar" style="height:100%;width:0%;background:var(--green);transition:width .3s"></div></div>
<div class="log-body" id="logBody"></div>
</div>
</div>
<div id="toast-area" style="position:fixed;top:54px;right:340px;z-index:200;display:flex;flex-direction:column;gap:6px"></div>
<!-- Inspector -->
<div class="inspector" id="inspector">
<div class="insp-tabs" id="inspTabs">
<div class="tab active" data-tab="inspect" onclick="switchInspTab('inspect')">Inspect</div>
<div class="tab" data-tab="files" onclick="switchInspTab('files')" id="tabFiles" style="display:none">Files</div>
<div class="tab" data-tab="exec" onclick="switchInspTab('exec')" id="tabExec" style="display:none">Execution <span id="historyBadge" style="display:none;font-size:9px;background:var(--bg-hover);padding:0 4px;border-radius:3px;margin-left:2px"></span></div>
<div class="tab" data-tab="report" onclick="switchInspTab('report')" id="tabReport" style="display:none">Report</div>
</div>
<div id="inspectContent">
<div class="empty">Click a resource to inspect</div>
</div>
<div id="filesContent" style="display:none"></div>
<div id="execContent" style="display:none"></div>
<div id="reportContent" style="display:none"></div>
</div>
</div>
<div class="info-bar" id="infoBar"></div>
</div>
<!-- Autocomplete popup -->
<div class="ac-popup" id="acPopup"></div>
<div class="file-picker-backdrop" id="filePickerBackdrop">
<div class="file-picker" onclick="event.stopPropagation()">
<div class="file-picker-hdr">
<span style="color:var(--accent)">Open Graph</span>
<span style="margin-left:auto;color:var(--text3);font-size:10px">Served from workspace only</span>
<button class="btn" onclick="closeFilePicker()" style="font-size:10px;padding:2px 8px">Close</button>
</div>
<input class="file-picker-search" id="filePickerSearch" type="text" placeholder="Filter .cgr / .cg files" oninput="renderFilePicker(this.value)">
<div class="file-picker-controls">
<label class="file-picker-filter" for="filePickerTagFilter">
<span>Show</span>
<select id="filePickerTagFilter" onchange="renderFilePicker(filePickerSearch.value)">
<option value="all">all files</option>
</select>
</label>
</div>
<div class="file-picker-list" id="filePickerList"></div>
</div>
</div>
<script>
// ── State ──────────────────────────────────────────────
let currentFile = null;
let isDirty = false;
let graphData = null;
let byId = {};
let depnts = {};
let selId = null;
let lineToRids = {}; // editor line → [resource IDs]
let ridToLine = {}; // resource ID → editor line
let editorHlLine = 0; // currently highlighted editor line (from graph hover)
let resolveTimer = null;
let templates = [];
let stepNames = [];
let collapsedNodes = {}; // node_name → true if collapsed
let allCollapsed = false; // global collapse state
let collapseInitDone = false; // true after first auto-collapse decision
let edgeMode = 'all'; // 'all' | 'selection' | 'off'
let edgeModeInitDone = false;
let acIdx = -1;
let applyPollTimer = null;
let applyCursor = 0;
let applyStopClicks = 0;
let availableGraphFiles = [];
let availableGraphFileEntries = [];
let filePickerTagOptions = [];
const codeEl = document.getElementById('code');
const hlEl = document.getElementById('highlight');
const lineNumEl = document.getElementById('lineNumbers');
const problemsPanel = document.getElementById('problemsPanel');
const wavesEl = document.getElementById('waves');
const emptyMsg = document.getElementById('emptyMsg');
const infoBar = document.getElementById('infoBar');
const inspEl = document.getElementById('inspectContent');
const execEl = document.getElementById('execContent');
const reportEl = document.getElementById('reportContent');
const statusBadge = document.getElementById('statusBadge');
const filenameEl = document.getElementById('filename');
const dirtyEl = document.getElementById('dirty');
const acPopup = document.getElementById('acPopup');
const applyBtn = document.getElementById('applyBtn');
const rerunBtn = document.getElementById('rerunBtn');
const filePickerBackdrop = document.getElementById('filePickerBackdrop');
const filePickerSearch = document.getElementById('filePickerSearch');
const filePickerTagFilter = document.getElementById('filePickerTagFilter');
const filePickerList = document.getElementById('filePickerList');
const filePickerBtn = document.getElementById('filePickerBtn');
let execInputWrap = null;
let execInputEl = null;
let execInputToggleBtn = null;
let csrfToken = null;
let vaultRetryPass = null;
let execInputTargetRid = null;
let execInputTargetName = null;
let runningStepMeta = new Map();
let runningStepTicker = null;
let applyHeartbeatTs = null;
let applyPollErrorTs = null;
// ── API helpers ────────────────────────────────────────
// Compute base path so API calls work through path-prefixed proxies (e.g. Coder).
// If served at /proxy/8420/ the base is "/proxy/8420"; if at / the base is "".
const _API_BASE = window.location.pathname.endsWith('/')
? window.location.pathname.slice(0, -1)
: window.location.pathname.replace(/\/[^/]*$/, '');
async function api(method, path, body) {
const opts = { method, headers: {'Content-Type':'application/json'} };
const upper = String(method || 'GET').toUpperCase();
if (!['GET', 'HEAD', 'OPTIONS'].includes(upper)) {
if (!csrfToken) {
const tr = await fetch(_API_BASE + '/api/csrf', { method: 'GET' });
const tj = await tr.json();
if (tj.error) return tj;
csrfToken = tj.csrf_token || null;
}
if (csrfToken) opts.headers['X-CSRF-Token'] = csrfToken;
}
if (body !== undefined) opts.body = JSON.stringify(body);
const r = await fetch(_API_BASE + path, opts);
const text = await r.text();
let data = null;
if (text) {
try {
data = JSON.parse(text);
} catch (_) {
data = null;
}
}
if (!r.ok) {
const msg = (data && data.error) ? data.error : (text ? text.slice(0, 300) : `${r.status} ${r.statusText}`);
return { error: `HTTP ${r.status}: ${msg}` };
}
if (data !== null) return data;
if (!text) return {};
return { error: `Invalid JSON response from ${path}: ${text.slice(0, 300)}` };
}
// ── File operations ────────────────────────────────────
async function loadFile(name) {
if (name) {
const openResp = await api('POST', '/api/file/open', { name });
if (openResp.error) { setStatus('err', openResp.error); return; }
}
const r = await api('GET', '/api/file' + (name ? '?name=' + encodeURIComponent(name) : ''));
if (r.error) { setStatus('err', r.error); return; }
currentFile = r.name;
codeEl.value = r.content;
filenameEl.textContent = r.name;
isDirty = false;
collapsedNodes = {}; collapseInitDone = false; allCollapsed = false;
edgeModeInitDone = false;
dirtyEl.style.display = 'none';
updateHighlight();
triggerResolve();
}
function renderFilePicker(filter = '') {
const q = String(filter || '').toLowerCase().trim();
const activeTag = filePickerTagFilter ? filePickerTagFilter.value : 'all';
const files = availableGraphFileEntries.filter(f => {
const matchesSearch = !q || f.name.toLowerCase().includes(q);
const tags = Array.isArray(f.tags) ? f.tags : [];
const matchesTag = activeTag === 'all' || tags.includes(activeTag);
return matchesSearch && matchesTag;
});
filePickerList.innerHTML = '';
if (!files.length) {
filePickerList.innerHTML = '<div class="file-picker-empty">No matching graph files</div>';
return;
}
files.forEach(file => {
const name = file.name;
const isActive = currentFile === name;
const label = name.split('/').pop();
const tags = Array.isArray(file.tags) ? file.tags : [];
const tagsHtml = tags.map(tag => `<span class="file-picker-tag ${esc(tag)}">${esc(tag)}</span>`).join('');
const item = document.createElement('div');
item.className = 'file-picker-item' + (isActive ? ' active' : '');
item.innerHTML = `<div class="file-picker-path"><span>${esc(label)}</span>${tagsHtml}</div><div class="file-picker-meta">${esc(name)}${isActive ? ' · current file' : ''}</div>`;
item.addEventListener('click', () => { void chooseFileFromPicker(name); });
filePickerList.appendChild(item);
});
}
function filePickerTagLabel(tag) {
const labels = {
all: 'all files',
root: 'root files',
example: 'examples',
testing: 'testing',
template: 'templates',
cgr: '.cgr',
cg: '.cg',
};
return labels[tag] || tag;
}
function refreshFilePickerTagOptions() {
if (!filePickerTagFilter) return;
const current = filePickerTagFilter.value || 'all';
const preferredOrder = ['root', 'example', 'testing', 'template', 'cgr', 'cg'];
const available = new Set();
availableGraphFileEntries.forEach(file => {
(file.tags || []).forEach(tag => available.add(tag));
});
filePickerTagOptions = preferredOrder.filter(tag => available.has(tag));
available.forEach(tag => {
if (!filePickerTagOptions.includes(tag)) filePickerTagOptions.push(tag);
});
const nextValue = current === 'all' || available.has(current) ? current : 'all';
filePickerTagFilter.innerHTML = `<option value="all">${esc(filePickerTagLabel('all'))}</option>`
+ filePickerTagOptions.map(tag => `<option value="${esc(tag)}">${esc(filePickerTagLabel(tag))}</option>`).join('');
filePickerTagFilter.value = nextValue;
}
function openFilePicker() {
if (!availableGraphFiles.length) return;
filePickerBackdrop.style.display = 'flex';
renderFilePicker(filePickerSearch.value || '');
filePickerSearch.focus();
filePickerSearch.select();
}
function closeFilePicker() {
filePickerBackdrop.style.display = 'none';
filePickerSearch.value = '';
}
async function chooseFileFromPicker(name) {
closeFilePicker();
await loadFile(name);
}
async function doSave() {
if (!currentFile) return;
const r = await api('PUT', '/api/file', { name: currentFile, content: codeEl.value });
if (r.ok) {
isDirty = false;
dirtyEl.style.display = 'none';
setStatus('ok', 'Saved');
} else {
setStatus('err', r.error || 'Save failed');
}
}
async function doCheck() {
const pp = document.getElementById('problemsPanel');
// Step 1: validate (resolve)
const r = await apiWithVaultRetry('POST', '/api/resolve', { source: codeEl.value });
if (r.error) {
setStatus('err', 'Invalid');
showProblems([{ severity: 'error', line: r.line || 0, name: 'parse', msg: r.error }]);
return;
}
// Step 2: lint (best-practice warnings)
try {
const lr = await apiWithVaultRetry('POST', '/api/lint', { source: codeEl.value });
const warnings = (lr.warnings || []);
if (warnings.length === 0) {
setStatus('ok', r.resources + ' resources, ' + r.waves + ' waves — no warnings');
hideProblems();
} else {
setStatus('warn', r.resources + ' res, ' + warnings.length + ' warning(s)');
showProblems(warnings);
}
} catch (e) {
// Lint failed but validation passed
setStatus('ok', r.resources + ' resources, ' + r.waves + ' waves');
hideProblems();
}
}
function linkifyFilePaths(msgHtml) {
// Make file paths in warning messages clickable if they match known external files
if (!currentExternalFiles.length) return msgHtml;
for (const f of currentExternalFiles) {
if (!f.exists) continue;
const escaped = f.path.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const re = new RegExp("'" + escaped + "'", 'g');
const replacement = "'<span class=\"prob-file-link\" data-resolved=\"" + esc(f.resolved)
+ "\" data-type=\"" + esc(f.type)
+ "\" data-path=\"" + esc(f.path)
+ "\">" + esc(f.path) + " ↗</span>'";
msgHtml = msgHtml.replace(re, replacement);
}
return msgHtml;
}
function showProblems(items) {
const pp = document.getElementById('problemsPanel');
const errs = items.filter(i => i.severity === 'error');
const warns = items.filter(i => i.severity !== 'error');
let html = '<div class="prob-summary"><span>';
if (errs.length) html += '<span style="color:var(--red)">' + errs.length + ' error(s)</span> ';
if (warns.length) html += '<span style="color:var(--amber)">' + warns.length + ' warning(s)</span>';
if (!errs.length && !warns.length) html += 'No problems';
html += '</span><span class="prob-close" onclick="hideProblems()">×</span></div>';
// Build provenance lookup: step name → template path
const provMap = {};
if (graphData && graphData.graph && graphData.graph.resources) {
for (const r of graphData.graph.resources) {
if (r.provenance) provMap[r.short_name] = r.provenance;
}
}
for (const item of items) {
const cls = item.severity === 'error' ? 'prob-err' : (item.severity === 'warn' ? 'prob-warn' : 'prob-info');
const icon = item.severity === 'error' ? '✖' : (item.severity === 'warn' ? '⚠' : 'ⓘ');
const loc = item.line ? 'line ' + item.line : '';
let msgHtml = linkifyFilePaths(esc(item.msg));
// If this step comes from a template, add a "View template" link
const tplPath = provMap[item.name];
const ef = tplPath ? currentExternalFiles.find(f => f.path === tplPath && f.exists) : null;
if (ef) {
msgHtml += ' <span class="prob-file-link" data-resolved="' + esc(ef.resolved)
+ '" data-type="' + esc(ef.type) + '" data-path="' + esc(ef.path)
+ '" data-step="' + esc(item.name || '')
+ '">View template ↗</span>';
}
html += '<div class="prob-item" onclick="scrollToLine(' + (item.line || 1) + ')">'
+ '<span class="prob-icon ' + cls + '">' + icon + '</span>'
+ '<span class="prob-msg">' + msgHtml + '</span>'
+ '<span class="prob-loc">' + esc(item.name || '') + (loc ? ' :' + item.line : '') + '</span>'
+ '</div>';
}
pp.innerHTML = html;
pp.style.display = 'block';
// Highlight error lines in gutter
if (errs.length && errs[0].line) {
lineNumEl.querySelectorAll('div').forEach(d => d.classList.remove('ln-err'));
const errDiv = lineNumEl.children[errs[0].line - 1];
if (errDiv) errDiv.classList.add('ln-err');
}
}
function hideProblems() {
document.getElementById('problemsPanel').style.display = 'none';
lineNumEl.querySelectorAll('div').forEach(d => d.classList.remove('ln-err'));
}
function scrollToLine(line) {
const lineHeight = 13 * 1.6;
codeEl.focus();
const container = document.getElementById('editorContainer');
const pos = (line - 1) * lineHeight;
container.scrollTop = Math.max(0, pos - container.clientHeight / 3);
}
// ── Resolve (live graph update) ────────────────────────
async function triggerResolve() {
clearTimeout(resolveTimer);
resolveTimer = setTimeout(async () => {
try {
const r = await apiWithVaultRetry('POST', '/api/resolve', { source: codeEl.value });
if (r.error) {
showError(r.error, r.line);
setStatus('err', 'Parse error');
} else {
hideError();
graphData = r;
renderGraph(r);
setStatus('ok', r.resources + ' res, ' + r.waves_count + ' waves');
// Update Files tab if there are external files
const ef = r.external_files || [];
if (ef.length > 0) {
document.getElementById('tabFiles').style.display = '';
renderFilesTab(ef);
// Auto-show Files tab on first load when inspector is at default state
// but NOT if the user is currently viewing the Execution tab
const inspDefault = document.querySelector('#inspectContent .empty');
const execTabActive = document.querySelector('.insp-tabs .tab[data-tab="exec"].active');
if (inspDefault && !execTabActive) switchInspTab('files');
} else {
document.getElementById('tabFiles').style.display = 'none';
}
}
} catch (e) {
console.error('Resolve failed:', e);
setStatus('err', 'Resolve failed: ' + (e.message || e));
}
}, 400);
}
function setStatus(type, text) {
statusBadge.className = 'status status-' + type;
statusBadge.textContent = text;
}
function promptForVaultPass(status) {
const msg = status === 'invalid'
? 'Vault passphrase was rejected. Enter the vault passphrase:'
: 'This graph needs a vault passphrase. Enter the vault passphrase:';
return window.prompt(msg, '');
}
async function apiWithVaultRetry(method, path, body) {
const payload = body ? { ...body } : {};
for (let attempt = 0; attempt < 3; attempt++) {
if (vaultRetryPass && payload.vault_pass === undefined) payload.vault_pass = vaultRetryPass;
const r = await api(method, path, payload);
if (!r || !r.needs_vault_pass) {
vaultRetryPass = null;
return r;
}
vaultRetryPass = null;
const entered = promptForVaultPass(r.vault_status || 'missing');
if (entered === null) return { error: r.error || 'Vault passphrase required', line: r.line || 0 };
vaultRetryPass = entered;
payload.vault_pass = entered;
}
return { error: 'Vault passphrase was rejected.' };
}
// ── Syntax highlighting ────────────────────────────────
function highlightSyntax(src) {
// Use marker tokens (\x01type\x02 ... \x03) so regex passes don't match
// the HTML class attributes generated by earlier passes.
let out = src
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
// Comments
out = out.replace(/^(\s*)(#.*)$/gm, '$1\x01comment\x02$2\x03');
// Title
out = out.replace(/^(---.+---)$/gm, '\x01title\x02$1\x03');
// Variables ${...}
out = out.replace(/(\$\{[^}]+\})/g, '\x01var\x02$1\x03');
// Strings "..."
out = out.replace(/"([^"]*)"/g, '\x01str\x02"$1"\x03');
// Step names [...]
out = out.replace(/\[([^\]]+)\]/g, '\x01step\x02[$1]\x03');
// Using lines: underline the path to hint it's clickable
out = out.replace(/^(\s*)(using)\s+(\S+)/gm, '$1\x01kw\x02$2\x03 \x01upath\x02$3\x03');
// from template lines: underline the template path
out = out.replace(/\b(from)\s+(\S+)\s*:/g, '\x01kw\x02$1\x03 \x01upath\x02$2\x03:');
// Keywords at line start
out = out.replace(/^(\s*)(set|target|template|verify|parallel|race|race into|each|stage|phase|first|needs|skip if|run|always run|env|when|description|as|timeout|retry|if fails|collect|tags|secrets|inventory|gather facts|get|post|put|patch|delete|auth|header|body|expect)\b/gm,
'$1\x01kw\x02$2\x03');
// $ command prefix
out = out.replace(/(\$\s)/g, '\x01prop\x02$1\x03');
// from keyword
out = out.replace(/\b(from)\s/g, '\x01kw\x02$1\x03 ');
// Convert markers to real spans
out = out.replace(/\x01(\w+)\x02/g, '<span class="hl-$1">').replace(/\x03/g, '</span>');
return out;
}
function updateHighlight() {
hlEl.innerHTML = highlightSyntax(codeEl.value) + '\n';
updateLineNumbers();
// Sync textarea height to highlight layer so clicks work after scrolling
requestAnimationFrame(() => {
codeEl.style.height = hlEl.offsetHeight + 'px';
});
}
function updateLineNumbers() {
const lines = codeEl.value.split('\n').length;
let html = '';
for (let i = 1; i <= lines; i++) {
html += '<div>' + i + '</div>';
}
lineNumEl.innerHTML = html;
}
function showError(msg, line) {
showProblems([{ severity: 'error', line: line || 0, name: 'parse', msg: msg }]);
}
function hideError() {
hideProblems();
}
function cycleEdgeMode() {
const modes = ['all', 'selection', 'off'];
edgeMode = modes[(modes.indexOf(edgeMode) + 1) % modes.length];
const btn = document.getElementById('bedges');
btn.innerHTML = '⟋ Edges: ' + edgeMode;
drawA();
}
function toggleCollapseAll() {
if (!graphData || !graphData.graph) return;
const nodeNames = Object.keys(graphData.graph.nodes || {});
allCollapsed = !allCollapsed;
collapsedNodes = {};
if (allCollapsed) nodeNames.forEach(nn => { collapsedNodes[nn] = true; });
renderGraph(graphData);
}
// ── Graph diff tracking ───────────────────────────────
let prevGraphSnapshot = {}; // id → {run, check, needs_str}
let diffAdded = new Set();
let diffChanged = new Set();
// ── Graph rendering ────────────────────────────────────
function renderGraph(data) {
wavesEl.innerHTML = '';
emptyMsg.style.display = 'none';
document.getElementById('graphToolbar').style.display = 'flex';
if (typeof demo !== 'undefined' && demo.state !== 'idle') demo.reset();
// Build current snapshot for diff (before overwriting byId)
const curSnapshot = {};
data.graph.resources.forEach(r => {
curSnapshot[r.id] = { run: r.run || '', check: r.check || '', needs: (r.needs||[]).join(',') };
});
// Compute diffs: added, removed, changed