-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin.html
More file actions
1050 lines (955 loc) · 44.5 KB
/
admin.html
File metadata and controls
1050 lines (955 loc) · 44.5 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>RAR Admin — Submission Pipeline</title>
<style>
:root {
--bg: #0d1117;
--surface: #161b22;
--surface2: #21262d;
--surface3: #30363d;
--border: #30363d;
--border-hover: #484f58;
--text: #e6edf3;
--text-dim: #8b949e;
--text-muted: #656d76;
--accent: #58a6ff;
--accent-bg: rgba(88,166,255,.1);
--green: #3fb950;
--green-bg: rgba(63,185,80,.12);
--orange: #d29922;
--orange-bg: rgba(210,153,34,.12);
--purple: #bc8cff;
--purple-bg: rgba(188,140,255,.12);
--red: #f85149;
--red-bg: rgba(248,81,73,.12);
--yellow: #e3b341;
--gold: #ffd700;
--shadow: 0 3px 12px rgba(0,0,0,.4);
--radius: 10px;
--radius-lg: 14px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: 'SF Mono', 'Fira Code', Consolas, monospace; }
/* Header */
header {
background: var(--surface); border-bottom: 1px solid var(--border);
padding: 14px 32px; display: flex; align-items: center; justify-content: space-between;
position: sticky; top: 0; z-index: 50;
}
.logo { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; font-weight: 700; }
.logo-mark {
background: linear-gradient(135deg, var(--orange), var(--red));
color: #fff; width: 32px; height: 32px; border-radius: 8px;
display: flex; align-items: center; justify-content: center;
font-size: .85rem; font-weight: 800;
}
.header-right { display: flex; align-items: center; gap: 12px; }
.back-link {
background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim);
padding: 6px 14px; border-radius: 8px; font-size: .85rem; cursor: pointer;
transition: all .15s; text-decoration: none;
}
.back-link:hover { border-color: var(--border-hover); color: var(--text); text-decoration: none; }
.refresh-btn {
background: var(--accent-bg); border: 1px solid rgba(88,166,255,.3); color: var(--accent);
padding: 6px 14px; border-radius: 8px; font-size: .85rem; cursor: pointer;
font-weight: 600; transition: all .15s;
}
.refresh-btn:hover { background: rgba(88,166,255,.2); }
.refresh-btn:disabled { opacity: .5; cursor: not-allowed; }
/* Stats bar */
.stats-bar {
display: flex; gap: 16px; padding: 16px 32px; border-bottom: 1px solid var(--border);
background: var(--surface); flex-wrap: wrap;
}
.stat-card {
background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
padding: 12px 20px; min-width: 140px; flex: 1;
}
.stat-card .stat-num { font-size: 1.8rem; font-weight: 700; }
.stat-card .stat-label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-pending .stat-num { color: var(--orange); }
.stat-approved .stat-num { color: var(--accent); }
.stat-merged .stat-num { color: var(--green); }
.stat-failed .stat-num { color: var(--red); }
.stat-total .stat-num { color: var(--purple); }
/* Pipeline board */
.container { max-width: 1400px; margin: 0 auto; padding: 24px 32px; }
.board-header {
display: flex; align-items: center; justify-content: space-between;
margin-bottom: 20px;
}
.board-header h2 { font-size: 1.3rem; font-weight: 700; }
.board-header .updated { color: var(--text-muted); font-size: .8rem; }
.pipeline {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 16px; align-items: start;
}
.column {
background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
overflow: hidden;
}
.col-header {
padding: 14px 16px; border-bottom: 1px solid var(--border);
display: flex; align-items: center; justify-content: space-between;
font-weight: 600; font-size: .9rem;
}
.col-header .col-count {
background: var(--surface2); padding: 2px 8px; border-radius: 10px;
font-size: .72rem; color: var(--text-dim); font-weight: 500;
}
.col-pending .col-header { border-top: 3px solid var(--orange); }
.col-review .col-header { border-top: 3px solid var(--accent); }
.col-merged .col-header { border-top: 3px solid var(--green); }
.col-failed .col-header { border-top: 3px solid var(--red); }
.col-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.col-empty { color: var(--text-muted); font-size: .82rem; text-align: center; padding: 24px 12px; }
/* Issue cards */
.issue-card {
background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
padding: 14px; transition: all .15s; cursor: pointer;
}
.issue-card:hover { border-color: var(--border-hover); transform: translateY(-1px); box-shadow: var(--shadow); }
.issue-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.issue-num { color: var(--text-muted); font-size: .78rem; font-family: 'SF Mono', Consolas, monospace; }
.issue-title { font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.issue-agent { font-family: 'SF Mono', Consolas, monospace; font-size: .78rem; color: var(--accent); margin-bottom: 8px; }
.issue-meta { display: flex; align-items: center; gap: 10px; font-size: .75rem; color: var(--text-muted); flex-wrap: wrap; }
.issue-avatar { width: 20px; height: 20px; border-radius: 50%; vertical-align: middle; }
.issue-label {
display: inline-block; padding: 1px 7px; border-radius: 10px;
font-size: .68rem; font-weight: 600; border: 1px solid;
}
.label-pending { background: var(--orange-bg); color: var(--orange); border-color: rgba(210,153,34,.3); }
.label-approved { background: var(--accent-bg); color: var(--accent); border-color: rgba(88,166,255,.3); }
.label-forged { background: var(--purple-bg); color: var(--purple); border-color: rgba(188,140,255,.3); }
.label-processed { background: var(--green-bg); color: var(--green); border-color: rgba(63,185,80,.3); }
.label-failed { background: var(--red-bg); color: var(--red); border-color: rgba(248,81,73,.3); }
/* Duplicates section */
.dupes-section { margin-top: 32px; }
.dupes-section h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 14px; }
.dupe-card {
background: var(--surface); border: 1px solid rgba(210,153,34,.3); border-radius: var(--radius);
padding: 14px 18px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between;
}
.dupe-card .dupe-name { font-weight: 600; font-size: .95rem; }
.dupe-card .dupe-agents { font-family: 'SF Mono', Consolas, monospace; font-size: .78rem; color: var(--text-dim); }
.dupe-badge {
background: var(--orange-bg); color: var(--orange); border: 1px solid rgba(210,153,34,.3);
padding: 2px 8px; border-radius: 10px; font-size: .72rem; font-weight: 600;
}
/* Recent activity log */
.activity-section { margin-top: 32px; }
.activity-section h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 14px; }
.activity-log {
background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
overflow: hidden;
}
.activity-row {
display: flex; align-items: center; gap: 14px; padding: 12px 16px;
border-bottom: 1px solid var(--border); font-size: .85rem;
transition: background .1s;
}
.activity-row:last-child { border-bottom: none; }
.activity-row:hover { background: var(--surface2); }
.activity-icon { font-size: 1rem; width: 24px; text-align: center; flex-shrink: 0; }
.activity-text { flex: 1; }
.activity-text strong { font-weight: 600; }
.activity-time { color: var(--text-muted); font-size: .78rem; white-space: nowrap; }
/* Action buttons */
.action-bar {
display: flex; gap: 6px; margin-top: 10px;
}
.action-btn {
flex: 1; padding: 6px 10px; border-radius: 6px; border: 1px solid;
font-size: .75rem; font-weight: 600; cursor: pointer; transition: all .15s;
text-align: center;
}
.action-btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-approve { background: var(--green-bg); color: var(--green); border-color: rgba(63,185,80,.3); }
.btn-approve:hover:not(:disabled) { background: rgba(63,185,80,.25); }
.btn-reject { background: var(--red-bg); color: var(--red); border-color: rgba(248,81,73,.3); }
.btn-reject:hover:not(:disabled) { background: rgba(248,81,73,.25); }
.btn-retry { background: var(--accent-bg); color: var(--accent); border-color: rgba(88,166,255,.3); }
.btn-retry:hover:not(:disabled) { background: rgba(88,166,255,.25); }
.btn-view { background: var(--surface2); color: var(--text-dim); border-color: var(--border); }
.btn-view:hover:not(:disabled) { color: var(--text); border-color: var(--border-hover); }
/* Auth */
.auth-bar {
display: flex; align-items: center; gap: 10px; padding: 10px 32px;
background: var(--surface); border-bottom: 1px solid var(--border);
font-size: .85rem;
}
/* Pipeline smoke test */
.smoke-test-section { margin-top: 32px; }
.smoke-test-section h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 14px; }
.smoke-log {
background: #0d1117; color: #c9d1d9; border: 1px solid var(--border);
border-radius: var(--radius-lg); padding: 16px; font-family: monospace;
font-size: .8rem; max-height: 400px; overflow-y: auto; white-space: pre-wrap;
}
.smoke-log .pass { color: #3fb950; }
.smoke-log .fail { color: #f85149; }
.smoke-log .info { color: #58a6ff; }
.smoke-log .warn { color: #d29922; }
.smoke-progress {
display: flex; gap: 8px; align-items: center; margin-bottom: 12px;
}
.smoke-progress .step {
width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center;
justify-content: center; font-size: .75rem; font-weight: 700; border: 2px solid var(--border);
color: var(--text-muted); background: var(--surface);
}
.smoke-progress .step.active { border-color: var(--accent); color: var(--accent); animation: pulse 1s infinite; }
.smoke-progress .step.done { border-color: var(--green); color: var(--green); background: var(--green-bg); }
.smoke-progress .step.fail { border-color: var(--red); color: var(--red); background: var(--red-bg); }
.smoke-progress .connector { flex: 1; height: 2px; background: var(--border); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
.auth-bar .gh-login {
display: inline-flex; align-items: center; gap: 6px;
background: var(--surface2); border: 1px solid var(--border); color: var(--text);
padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: .82rem;
transition: all .15s;
}
.auth-bar .gh-login:hover { border-color: var(--border-hover); background: var(--surface3); }
.auth-bar .gh-login svg { width: 16px; height: 16px; fill: currentColor; }
.user-pill {
display: inline-flex; align-items: center; gap: 6px;
background: var(--surface2); border: 1px solid var(--border);
padding: 3px 10px 3px 3px; border-radius: 16px; font-size: .82rem;
}
.user-pill img { width: 22px; height: 22px; border-radius: 50%; }
.user-pill .logout { color: var(--text-muted); cursor: pointer; margin-left: 4px; font-size: .72rem; }
.user-pill .logout:hover { color: var(--red); }
/* Toast */
.toast {
position: fixed; bottom: 24px; right: 24px; padding: 12px 20px;
border-radius: 8px; font-size: .85rem; font-weight: 500; z-index: 100;
animation: slideIn .3s ease-out; max-width: 360px;
}
.toast-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(63,185,80,.3); }
.toast-error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(248,81,73,.3); }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.loading { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.spinner {
width: 28px; height: 28px; border: 3px solid var(--surface3);
border-top-color: var(--accent); border-radius: 50%;
animation: spin .8s linear infinite; display: inline-block; margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 900px) {
.pipeline { grid-template-columns: 1fr 1fr; }
.stats-bar { padding: 12px 16px; }
.container { padding: 16px; }
}
@media (max-width: 600px) {
.pipeline { grid-template-columns: 1fr; }
header { padding: 12px 16px; }
}
</style>
</head>
<body>
<header>
<div class="logo">
<div class="logo-mark">R</div>
<span>RAR Admin</span>
</div>
<div class="header-right">
<a href="index.html" class="back-link">← Back to Registry</a>
<button class="refresh-btn" onclick="loadPipeline()" id="refresh-btn">↻ Refresh</button>
</div>
</header>
<div class="auth-bar" id="auth-bar">
<span style="color:var(--text-muted)">Sign in to approve, reject, or retry submissions →</span>
<button class="gh-login" id="login-btn" onclick="loginWithGitHub()">
<svg viewBox="0 0 16 16"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
Sign in with GitHub
</button>
</div>
<div class="stats-bar" id="stats-bar">
<div class="stat-card stat-pending"><div class="stat-num" id="stat-pending">–</div><div class="stat-label">Pending Review</div></div>
<div class="stat-card stat-approved"><div class="stat-num" id="stat-approved">–</div><div class="stat-label">Approved</div></div>
<div class="stat-card stat-merged"><div class="stat-num" id="stat-merged">–</div><div class="stat-label">Merged</div></div>
<div class="stat-card stat-failed"><div class="stat-num" id="stat-failed">–</div><div class="stat-label">Failed</div></div>
<div class="stat-card stat-total"><div class="stat-num" id="stat-total">–</div><div class="stat-label">Total Submissions</div></div>
</div>
<div class="container">
<div class="board-header">
<h2>🔄 Submission Pipeline</h2>
<span class="updated" id="last-updated"></span>
</div>
<div id="pipeline-loading" class="loading">
<div class="spinner"></div><br>Loading pipeline from GitHub…
</div>
<div class="pipeline" id="pipeline" style="display:none">
<div class="column col-pending">
<div class="col-header">📥 Pending Review <span class="col-count" id="cnt-pending">0</span></div>
<div class="col-body" id="col-pending"></div>
</div>
<div class="column col-review">
<div class="col-header">🔍 Approved / In Progress <span class="col-count" id="cnt-review">0</span></div>
<div class="col-body" id="col-review"></div>
</div>
<div class="column col-merged">
<div class="col-header">✅ Merged <span class="col-count" id="cnt-merged">0</span></div>
<div class="col-body" id="col-merged"></div>
</div>
<div class="column col-failed">
<div class="col-header">❌ Failed <span class="col-count" id="cnt-failed">0</span></div>
<div class="col-body" id="col-failed"></div>
</div>
</div>
<div class="dupes-section" id="dupes-section" style="display:none">
<h3>⚠️ Duplicate Agents</h3>
<div id="dupes-list"></div>
</div>
<div class="smoke-test-section" id="smoke-section" style="display:none">
<h3>🧪 Pipeline Smoke Test</h3>
<div class="smoke-progress" id="smoke-steps">
<div class="step" id="ss-1" title="Create test issue">1</div><div class="connector"></div>
<div class="step" id="ss-2" title="Wait for staging">2</div><div class="connector"></div>
<div class="step" id="ss-3" title="Approve">3</div><div class="connector"></div>
<div class="step" id="ss-4" title="Wait for forge">4</div><div class="connector"></div>
<div class="step" id="ss-5" title="Verify & cleanup">5</div>
</div>
<div class="smoke-log" id="smoke-log">Pipeline smoke test ready. Click "Run Smoke Test" to begin.\n</div>
<div style="margin-top:12px;display:flex;gap:8px">
<button class="action-btn btn-approve" id="smoke-run-btn" onclick="runSmokeTest()">▶ Run Smoke Test</button>
<button class="action-btn btn-view" onclick="document.getElementById('smoke-log').textContent=''">Clear Log</button>
</div>
</div>
<div class="activity-section">
<h3>📋 Recent Activity</h3>
<div class="activity-log" id="activity-log"></div>
</div>
</div>
<script>
const OWNER = 'kody-w';
const REPO = 'RAR';
const API = `https://api.github.com/repos/${OWNER}/${REPO}`;
const AUTH_CLIENT_ID = 'Ov23liuueQBIUggrH8NG';
const AUTH_WORKER_URL = 'https://rappterbook-auth.kwildfeuer.workers.dev';
let ghToken = localStorage.getItem('rb_access_token') || localStorage.getItem('gh_token');
let ghUser = null;
function esc(s) { const d = document.createElement('div'); d.textContent = s; return d.innerHTML; }
function showToast(msg, type = 'success') {
const t = document.createElement('div');
t.className = `toast toast-${type}`;
t.textContent = msg;
document.body.appendChild(t);
setTimeout(() => t.remove(), 4000);
}
function timeAgo(iso) {
const d = new Date(iso), now = new Date();
const mins = Math.floor((now - d) / 60000);
if (mins < 1) return 'just now';
if (mins < 60) return `${mins}m ago`;
const hrs = Math.floor(mins / 60);
if (hrs < 24) return `${hrs}h ago`;
const days = Math.floor(hrs / 24);
if (days === 1) return 'yesterday';
if (days < 7) return `${days}d ago`;
if (days < 30) return `${Math.floor(days / 7)}w ago`;
return d.toLocaleDateString();
}
function extractAgentName(title) {
const m = title.match(/\[AGENT\]\s*(@[\w-]+\/[\w_-]+)/);
return m ? m[1] : null;
}
function classifyIssue(issue) {
const labels = (issue.labels || []).map(l => typeof l === 'string' ? l : l.name);
if (labels.includes('smoke-test') && issue.state === 'closed') return 'closed';
if (labels.includes('duplicate') || labels.includes('rejected')) return 'closed';
if (labels.includes('failed')) return 'failed';
if (labels.includes('processed') || labels.includes('forged')) return 'merged';
if (labels.includes('approved') && issue.state === 'open') return 'review';
if (issue.state === 'closed') return 'closed';
return 'pending';
}
function labelHtml(name) {
const cls = name === 'pending-review' ? 'pending'
: name === 'approved' ? 'approved'
: name === 'forged' ? 'forged'
: name === 'processed' ? 'processed'
: name === 'failed' ? 'failed' : 'pending';
return `<span class="issue-label label-${cls}">${esc(name)}</span>`;
}
function issueCard(issue, stage) {
const agentName = extractAgentName(issue.title);
const labels = (issue.labels || []).map(l => typeof l === 'string' ? l : l.name);
const num = issue.number;
const disabled = !ghToken ? 'disabled title="Sign in to take action"' : '';
let actions = '';
if (stage === 'pending') {
actions = `<div class="action-bar">
<button class="action-btn btn-approve" ${disabled} onclick="event.stopPropagation();approveIssue(${num})">✓ Approve</button>
<button class="action-btn btn-reject" ${disabled} onclick="event.stopPropagation();rejectIssue(${num})">✕ Reject</button>
<button class="action-btn btn-view" onclick="event.stopPropagation();window.open('${issue.html_url}','_blank')">View</button>
</div>`;
} else if (stage === 'review') {
actions = `<div class="action-bar">
<span style="color:var(--green);font-size:.78rem;font-weight:500">⏳ CI processing…</span>
<button class="action-btn btn-view" onclick="event.stopPropagation();window.open('${issue.html_url}','_blank')">View</button>
</div>`;
} else if (stage === 'failed') {
actions = `<div class="action-bar">
<button class="action-btn btn-retry" ${disabled} onclick="event.stopPropagation();retryIssue(${num})">↻ Retry</button>
<button class="action-btn btn-view" onclick="event.stopPropagation();window.open('${issue.html_url}','_blank')">View</button>
</div>`;
}
return `
<div class="issue-card" onclick="window.open('${issue.html_url}','_blank')">
<div class="issue-top">
<span class="issue-num">#${num}</span>
<span style="font-size:.72rem;color:var(--text-muted)">${timeAgo(issue.created_at)}</span>
</div>
${agentName ? `<div class="issue-agent">${esc(agentName)}</div>` : `<div class="issue-title">${esc(issue.title.replace(/^\[AGENT\]\s*/, '').replace(/^\[RAR\]\s*/, ''))}</div>`}
<div class="issue-meta">
<span>
<img class="issue-avatar" src="${issue.user.avatar_url}&s=40" alt="">
${esc(issue.user.login)}
</span>
${labels.map(l => labelHtml(l)).join(' ')}
</div>
${actions}
</div>`;
}
function activityIcon(issue) {
const stage = classifyIssue(issue);
if (stage === 'merged') return '✅';
if (stage === 'failed') return '❌';
if (stage === 'review') return '🔍';
return '📥';
}
function authHeaders() {
return ghToken ? { Authorization: `Bearer ${ghToken}`, Accept: 'application/vnd.github+json' } : {};
}
// ─── Actions ────────────────────────────────────────
async function approveIssue(num) {
if (!ghToken) return showToast('Sign in first', 'error');
try {
// Add approved label — triggers approve-agent.yml automatically
const labelResp = await fetch(`${API}/issues/${num}/labels`, {
method: 'POST', headers: { ...authHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ labels: ['approved'] })
});
if (!labelResp.ok) throw new Error(`Label failed: ${labelResp.status}`);
const commentResp = await fetch(`${API}/issues/${num}/comments`, {
method: 'POST', headers: { ...authHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ body: `✅ Approved by @${ghUser.login} via RAR Admin` })
});
if (!commentResp.ok) throw new Error(`Comment failed: ${commentResp.status}`);
showToast(`#${num} approved — CI will promote & forge`, 'success');
setTimeout(loadPipeline, 30000);
} catch (e) { showToast(`Failed: ${e.message}`, 'error'); }
}
async function rejectIssue(num) {
if (!ghToken) return showToast('Sign in first', 'error');
if (!confirm(`Reject and close issue #${num}?`)) return;
try {
await fetch(`${API}/issues/${num}/comments`, {
method: 'POST', headers: { ...authHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ body: `❌ Rejected by @${ghUser.login} via RAR Admin` })
});
await fetch(`${API}/issues/${num}`, {
method: 'PATCH', headers: { ...authHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ state: 'closed', labels: ['rejected'] })
});
showToast(`#${num} rejected`, 'success');
loadPipeline();
} catch (e) { showToast(`Failed: ${e.message}`, 'error'); }
}
async function processIssue(num) {
if (!ghToken) return showToast('Sign in first', 'error');
try {
// Trigger the process-issues workflow with this issue number
await fetch(`${API}/actions/workflows/process-issues.yml/dispatches`, {
method: 'POST', headers: { ...authHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ ref: 'main', inputs: { issue_number: String(num) } })
});
showToast(`#${num} processing triggered — check back in a minute`, 'success');
setTimeout(loadPipeline, 30000);
} catch (e) { showToast(`Failed: ${e.message}`, 'error'); }
}
async function retryIssue(num) {
if (!ghToken) return showToast('Sign in first', 'error');
try {
// Fetch issue to check if it's an agent submission
const issueResp = await fetch(`${API}/issues/${num}`, { headers: authHeaders() });
const issue = issueResp.ok ? await issueResp.json() : {};
const isAgent = (issue.title || '').startsWith('[AGENT]');
// Reopen the issue
await fetch(`${API}/issues/${num}`, {
method: 'PATCH', headers: { ...authHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ state: 'open' })
});
// Remove failed label
try {
await fetch(`${API}/issues/${num}/labels/failed`, {
method: 'DELETE', headers: authHeaders()
});
} catch {}
// Restore labels — include agent-submission if it's an [AGENT] issue
const restoreLabels = isAgent ? ['pending-review', 'agent-submission'] : ['pending-review'];
await fetch(`${API}/issues/${num}/labels`, {
method: 'POST', headers: { ...authHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ labels: restoreLabels })
});
await fetch(`${API}/issues/${num}/comments`, {
method: 'POST', headers: { ...authHeaders(), 'Content-Type': 'application/json' },
body: JSON.stringify({ body: `↻ Retried by @${ghUser.login} via RAR Admin — reopened for review` })
});
showToast(`#${num} reopened for review`, 'success');
loadPipeline();
} catch (e) { showToast(`Failed: ${e.message}`, 'error'); }
}
// ─── Auth ───────────────────────────────────────────
function loginWithGitHub() {
const redirect = window.location.origin + window.location.pathname;
window.location.href = `https://github.com/login/oauth/authorize?client_id=${AUTH_CLIENT_ID}&scope=public_repo&redirect_uri=${encodeURIComponent(redirect)}`;
}
async function handleAuthCallback() {
const params = new URLSearchParams(window.location.search);
const code = params.get('code');
if (!code) return;
window.history.replaceState({}, '', window.location.href.split('?')[0]);
try {
const resp = await fetch(AUTH_WORKER_URL + '/api/auth/token', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ code }),
});
const data = await resp.json();
if (data.access_token) {
ghToken = data.access_token;
localStorage.setItem('rb_access_token', ghToken);
checkAuth();
showToast('Signed in!', 'success');
}
} catch (e) { showToast('Sign-in failed', 'error'); }
}
function checkAuth() {
if (!ghToken) return;
fetch('https://api.github.com/user', { headers: { Authorization: `Bearer ${ghToken}` } })
.then(r => r.ok ? r.json() : null)
.then(u => {
if (u) { ghUser = u; renderAuthBar(); }
else { ghToken = null; localStorage.removeItem('rb_access_token'); localStorage.removeItem('gh_token'); }
}).catch(() => {});
}
function logout() {
ghToken = null; ghUser = null;
localStorage.removeItem('rb_access_token');
localStorage.removeItem('gh_token');
renderAuthBar();
loadPipeline();
showToast('Signed out', 'success');
}
function renderAuthBar() {
const bar = document.getElementById('auth-bar');
const smokeSection = document.getElementById('smoke-section');
if (ghUser) {
bar.innerHTML = `
<span style="color:var(--green)">● Signed in</span>
<div class="user-pill">
<img src="${ghUser.avatar_url}&s=44" alt="">
<span>@${ghUser.login}</span>
<span class="logout" onclick="logout()">sign out</span>
</div>
<span style="color:var(--text-muted);font-size:.78rem;margin-left:8px">You can approve, reject, process, and retry submissions</span>`;
if (smokeSection) smokeSection.style.display = 'block';
} else {
bar.innerHTML = `
<span style="color:var(--text-muted)">Sign in to approve, reject, or retry submissions →</span>
<button class="gh-login" onclick="loginWithGitHub()">
<svg viewBox="0 0 16 16"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>
Sign in with GitHub</button>`;
if (smokeSection) smokeSection.style.display = 'none';
}
}
// ─── Pipeline ───────────────────────────────────────
async function loadPipeline() {
const btn = document.getElementById('refresh-btn');
btn.disabled = true;
btn.textContent = '↻ Loading…';
try {
const headers = ghToken ? { Authorization: `Bearer ${ghToken}` } : {};
const [openRes, closedRes] = await Promise.all([
fetch(`${API}/issues?state=open&per_page=100&sort=created&direction=desc`, { headers }),
fetch(`${API}/issues?state=closed&per_page=100&sort=created&direction=desc`, { headers })
]);
const openIssues = await openRes.json();
const closedIssues = await closedRes.json();
const all = [...openIssues, ...closedIssues]
.filter(i => !i.pull_request)
.filter(i => i.title.startsWith('[AGENT]'))
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
const buckets = { pending: [], review: [], merged: [], failed: [] };
for (const issue of all) {
const stage = classifyIssue(issue);
if (stage === 'closed') continue;
buckets[stage].push(issue);
}
document.getElementById('stat-pending').textContent = buckets.pending.length;
document.getElementById('stat-approved').textContent = buckets.review.length;
document.getElementById('stat-merged').textContent = buckets.merged.length;
document.getElementById('stat-failed').textContent = buckets.failed.length;
document.getElementById('stat-total').textContent = all.length;
for (const [stage, issues] of Object.entries(buckets)) {
const col = document.getElementById(`col-${stage}`);
const cnt = document.getElementById(`cnt-${stage}`);
cnt.textContent = issues.length;
col.innerHTML = issues.length
? issues.map(i => issueCard(i, stage)).join('')
: '<div class="col-empty">No submissions</div>';
}
const recent = all.slice(0, 20);
document.getElementById('activity-log').innerHTML = recent.length
? recent.map(i => `
<div class="activity-row" style="cursor:pointer" onclick="window.open('${i.html_url}','_blank')">
<span class="activity-icon">${activityIcon(i)}</span>
<div class="activity-text">
<img class="issue-avatar" src="${i.user.avatar_url}&s=32" alt="" style="margin-right:4px">
<strong>${esc(i.user.login)}</strong> submitted
<code>${esc(extractAgentName(i.title) || i.title)}</code>
</div>
<span class="activity-time">${timeAgo(i.created_at)}</span>
</div>`).join('')
: '<div class="col-empty" style="padding:20px">No activity yet</div>';
document.getElementById('pipeline-loading').style.display = 'none';
document.getElementById('pipeline').style.display = 'grid';
document.getElementById('last-updated').textContent = `Updated ${new Date().toLocaleTimeString()}`;
// Load duplicates from registry.json
loadDuplicates();
} catch (err) {
document.getElementById('pipeline-loading').innerHTML =
`<div style="color:var(--red)">Failed to load: ${esc(err.message)}</div>
<p style="margin-top:8px;color:var(--text-muted);font-size:.85rem">GitHub API may be rate-limited. Try again in a minute.</p>`;
} finally {
btn.disabled = false;
btn.textContent = '↻ Refresh';
}
}
// ─── Duplicates ─────────────────────────────────────
async function loadDuplicates() {
const section = document.getElementById('dupes-section');
const list = document.getElementById('dupes-list');
try {
const RAW = `https://raw.githubusercontent.com/${OWNER}/${REPO}/main`;
const resp = await fetch(`${RAW}/registry.json`);
const reg = await resp.json();
// Check registry-level duplicates from build
const buildDupes = reg.duplicates || [];
// Also scan for display_name collisions client-side (catches cross-source dupes)
const agents = reg.agents || [];
const byDisplay = {};
for (const a of agents) {
const dn = a.display_name;
if (!byDisplay[dn]) byDisplay[dn] = [];
byDisplay[dn].push(a.name);
}
const clientDupes = Object.entries(byDisplay)
.filter(([, names]) => names.length > 1)
.map(([dn, names]) => ({ display_name: dn, agents: names }));
// Merge (prefer client-side as it's more current)
const allDupes = clientDupes.length ? clientDupes : buildDupes;
if (!allDupes.length) {
section.style.display = 'none';
return;
}
section.style.display = 'block';
list.innerHTML = allDupes.map(d => `
<div class="dupe-card">
<div>
<div class="dupe-name">"${esc(d.display_name)}" <span class="dupe-badge">${d.agents.length} copies</span></div>
<div class="dupe-agents">${d.agents.map(n => esc(n)).join(' · ')}</div>
</div>
</div>`).join('');
} catch (e) {
section.style.display = 'none';
}
}
// ─── Pipeline Smoke Test ────────────────────────────
const SMOKE_AGENT_CODE = `"""
Pipeline Smoke Test Agent — DO NOT USE. Created by automated testing.
This agent is created and destroyed by the admin pipeline smoke test.
"""
__manifest__ = {
"schema": "rapp-agent/1.0",
"name": "@rapp/_smoke_test_agent",
"version": "1.0.0",
"display_name": "SmokeTestAgent",
"description": "Automated pipeline smoke test — created and destroyed by CI testing.",
"author": "RAR Pipeline",
"tags": ["test", "smoke", "pipeline"],
"category": "devtools",
"quality_tier": "community",
"requires_env": [],
"dependencies": ["@rapp/basic_agent"],
}
try:
from agents.basic_agent import BasicAgent
except ModuleNotFoundError:
class BasicAgent:
def __init__(self, name="", metadata=None): self.name = name; self.metadata = metadata or {}
def perform(self, **kw): return ""
class SmokeTestAgent(BasicAgent):
def __init__(self):
self.name = "SmokeTestAgent"
self.metadata = {"description": __manifest__["description"], "parameters": {"type": "object", "properties": {"operation": {"type": "string", "enum": ["ping"]}}}}
super().__init__(name=self.name, metadata=self.metadata)
def perform(self, **kwargs) -> str:
return "pong — smoke test passed"
if __name__ == "__main__":
agent = SmokeTestAgent()
print(agent.perform(operation="ping"))
`;
let smokeRunning = false;
function slog(msg, cls = '') {
const el = document.getElementById('smoke-log');
const span = document.createElement('span');
if (cls) span.className = cls;
span.textContent = msg + '\n';
el.appendChild(span);
el.scrollTop = el.scrollHeight;
}
function setStep(n, state) {
const el = document.getElementById(`ss-${n}`);
if (el) { el.className = 'step ' + state; }
}
async function ghFetch(path, opts = {}) {
const resp = await fetch(`${API}${path}`, {
...opts,
headers: { ...authHeaders(), 'Content-Type': 'application/json', ...(opts.headers || {}) },
});
return resp;
}
async function pollForLabel(issueNum, label, timeoutMs = 120000) {
const start = Date.now();
while (Date.now() - start < timeoutMs) {
const resp = await ghFetch(`/issues/${issueNum}/labels`);
if (resp.ok) {
const labels = await resp.json();
if (labels.some(l => l.name === label)) return true;
}
await new Promise(r => setTimeout(r, 8000));
slog(` ⏳ waiting for "${label}" label... (${Math.round((Date.now() - start) / 1000)}s)`);
}
return false;
}
async function pollForFile(filePath, timeoutMs = 120000) {
const start = Date.now();
const rawUrl = `https://raw.githubusercontent.com/${OWNER}/${REPO}/main/${filePath}`;
while (Date.now() - start < timeoutMs) {
const resp = await fetch(rawUrl + '?t=' + Date.now());
if (resp.ok) return true;
await new Promise(r => setTimeout(r, 10000));
slog(` ⏳ waiting for file on main... (${Math.round((Date.now() - start) / 1000)}s)`);
}
return false;
}
async function runSmokeTest() {
if (!ghToken || !ghUser) return showToast('Sign in first', 'error');
if (smokeRunning) return showToast('Test already running', 'error');
smokeRunning = true;
const btn = document.getElementById('smoke-run-btn');
btn.disabled = true;
btn.textContent = '⏳ Running…';
document.getElementById('smoke-log').textContent = '';
for (let i = 1; i <= 5; i++) setStep(i, '');
const startTime = Date.now();
let issueNum = null;
try {
// ── Pre-flight: ensure staging is empty ──
slog('Pre-flight: checking staging directory…', 'info');
const stagingCheck = await ghFetch('/contents/staging');
if (stagingCheck.ok) {
const stagingFiles = await stagingCheck.json();
const pyFiles = stagingFiles.filter(f => f.name.endsWith('.py'));
if (pyFiles.length > 0) {
slog(` ✗ Staging has ${pyFiles.length} pending file(s) — aborting to avoid accidental promotion`, 'fail');
slog(' Clear staging or approve pending submissions first.', 'warn');
throw new Error('Staging not empty');
}
}
slog(' ✓ Staging is clean', 'pass');
// ── Step 1: Create test issue ──
setStep(1, 'active');
slog('Step 1: Creating test submission issue…', 'info');
const issueBody = '```json\n' + JSON.stringify({
action: 'submit_agent',
payload: { code: SMOKE_AGENT_CODE }
}, null, 2) + '\n```';
const createResp = await ghFetch('/issues', {
method: 'POST',
body: JSON.stringify({
title: '[AGENT] @rapp/_smoke_test_agent',
body: issueBody,
labels: ['smoke-test'],
}),
});
if (!createResp.ok) throw new Error(`Failed to create issue: ${createResp.status}`);
const issue = await createResp.json();
issueNum = issue.number;
slog(` ✓ Created issue #${issueNum}`, 'pass');
setStep(1, 'done');
// ── Step 2: Wait for process-issues.yml to stage it ──
setStep(2, 'active');
slog('Step 2: Waiting for CI to stage (pending-review label)…', 'info');
const staged = await pollForLabel(issueNum, 'pending-review', 180000);
if (!staged) {
// Check if it went straight to failed
const resp = await ghFetch(`/issues/${issueNum}/labels`);
const labels = resp.ok ? (await resp.json()).map(l => l.name) : [];
if (labels.includes('failed')) {
slog(' ✗ CI marked as failed — check workflow logs', 'fail');
throw new Error('Staging failed');
}
slog(' ✗ Timed out waiting for staging (3 min)', 'fail');
throw new Error('Staging timeout');
}
slog(' ✓ Agent staged for review', 'pass');
setStep(2, 'done');
// ── Step 3: Approve (add label to trigger approve-agent.yml) ──
setStep(3, 'active');
slog('Step 3: Approving — adding "approved" label…', 'info');
await ghFetch(`/issues/${issueNum}/labels`, {
method: 'POST',
body: JSON.stringify({ labels: ['approved'] }),
});
slog(' ✓ Approved label added — approve-agent.yml should trigger', 'pass');
setStep(3, 'done');
// ── Step 4: Wait for forge (approved + forged labels, issue closed) ──
setStep(4, 'active');
slog('Step 4: Waiting for approve-agent.yml to forge…', 'info');
const forged = await pollForLabel(issueNum, 'forged', 180000);
if (!forged) {
slog(' ✗ Timed out waiting for forge (3 min)', 'fail');
throw new Error('Forge timeout');
}
slog(' ✓ Agent forged by CI', 'pass');
// Verify file exists on main
slog(' Verifying agent file on main branch…', 'info');
const fileExists = await pollForFile('agents/@rapp/_smoke_test_agent.py', 60000);
if (!fileExists) {
slog(' ✗ Agent file not found on main after forge', 'fail');
throw new Error('File not committed');
}
slog(' ✓ Agent file verified on main', 'pass');
setStep(4, 'done');
// ── Step 5: Cleanup ──
setStep(5, 'active');
slog('Step 5: Cleaning up test artifacts…', 'info');
// Delete agent file via Contents API (no [skip ci] so build-registry runs)
const fileResp = await ghFetch('/contents/agents/@rapp/_smoke_test_agent.py');
if (fileResp.ok) {
const fileData = await fileResp.json();
await ghFetch('/contents/agents/@rapp/_smoke_test_agent.py', {
method: 'DELETE',
body: JSON.stringify({
message: 'Smoke test cleanup: remove _smoke_test_agent',
sha: fileData.sha,
}),
});
slog(' ✓ Deleted agent file (registry rebuild will trigger)', 'pass');
}
// Clean staging if it exists
const stagingResp = await ghFetch('/contents/staging/@rapp/_smoke_test_agent.py');
if (stagingResp.ok) {
const stagingData = await stagingResp.json();
await ghFetch('/contents/staging/@rapp/_smoke_test_agent.py', {
method: 'DELETE',
body: JSON.stringify({
message: 'Smoke test cleanup: remove staging [skip ci]',
sha: stagingData.sha,
}),
});
slog(' ✓ Deleted staging file', 'pass');
}
// Clean up any .card file
const cardResp = await ghFetch('/contents/agents/@rapp/_smoke_test_agent.py.card');
if (cardResp.ok) {
const cardData = await cardResp.json();
await ghFetch('/contents/agents/@rapp/_smoke_test_agent.py.card', {
method: 'DELETE',
body: JSON.stringify({
message: 'Smoke test cleanup: remove card [skip ci]',
sha: cardData.sha,
}),
});
slog(' ✓ Deleted card file', 'pass');
}
// Close the test issue
await ghFetch(`/issues/${issueNum}`, {
method: 'PATCH',
body: JSON.stringify({ state: 'closed', labels: ['smoke-test', 'processed'] }),
});
await ghFetch(`/issues/${issueNum}/comments`, {
method: 'POST',
body: JSON.stringify({ body: '🧪 Smoke test completed successfully. All artifacts cleaned up.' }),
});
slog(' ✓ Test issue closed', 'pass');
setStep(5, 'done');
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
slog(`\n━━━ PIPELINE SMOKE TEST PASSED ━━━ (${elapsed}s)`, 'pass');
showToast('Smoke test passed! ✓', 'success');
} catch (err) {
const failStep = [1,2,3,4,5].find(i => document.getElementById(`ss-${i}`)?.classList.contains('active'));
if (failStep) setStep(failStep, 'fail');