-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcrons.html
More file actions
1267 lines (1125 loc) · 43.5 KB
/
crons.html
File metadata and controls
1267 lines (1125 loc) · 43.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>Cron Jobs — Clawd Control</title>
<style>
/* ═══════════════════════════════════════════
CRONS — Page-specific styles
Layout, sidebar, topbar, theme, design system
provided by layout.js
═══════════════════════════════════════════ */
/* ── Page Layout ───────────────────────── */
.page-header {
margin-bottom: 24px;
}
.page-header h1 {
font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em;
display: flex; align-items: center; gap: 10px;
}
.page-header p {
font-size: 0.82rem; color: var(--text-tertiary); margin-top: 4px;
}
/* ── Stats Grid ────────────────────────── */
.stats-grid {
display: grid; grid-template-columns: repeat(4, 1fr);
gap: 12px; margin-bottom: 16px;
}
.stat-card {
background: var(--surface); border: 1px solid var(--border-subtle);
border-radius: var(--radius-md); padding: 14px 16px;
transition: all 0.35s ease;
}
.stat-card:hover { border-color: var(--border); }
[data-theme="light"] .stat-card { box-shadow: var(--shadow-sm); }
.stat-label {
font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em;
color: var(--text-tertiary); margin-bottom: 4px; font-weight: 600;
}
.stat-value {
font-size: 1.5rem; font-weight: 800; line-height: 1;
font-variant-numeric: tabular-nums;
}
.stat-value.accent { color: var(--accent); }
.stat-value.success { color: var(--success); }
.stat-value.info { color: var(--info); }
.stat-sub { font-size: 0.7rem; color: var(--text-tertiary); margin-top: 4px; }
/* ── Controls Bar ──────────────────────── */
.controls {
display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
margin-bottom: 16px; padding: 12px 16px;
background: var(--surface); border: 1px solid var(--border-subtle);
border-radius: var(--radius-md);
}
.control-group { display: flex; align-items: center; gap: 6px; }
.control-label {
font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
letter-spacing: 0.06em; color: var(--text-tertiary);
}
.control-select {
padding: 6px 10px; border-radius: var(--radius-sm);
background: var(--bg-primary); border: 1px solid var(--border-subtle);
color: var(--text-primary); font-family: var(--font-sans);
font-size: 0.8rem; cursor: pointer;
}
.control-select:focus { border-color: var(--accent); outline: none; }
.control-checkbox {
display: flex; align-items: center; gap: 6px; cursor: pointer;
font-size: 0.75rem; color: var(--text-secondary);
}
.control-checkbox input {
cursor: pointer;
}
/* ── Timeline ──────────────────────────── */
.timeline-container {
background: var(--surface); border: 1px solid var(--border-subtle);
border-radius: var(--radius-md); padding: 16px; margin-bottom: 16px;
}
.timeline-header {
display: flex; justify-content: space-between; align-items: center;
margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border-subtle);
}
.timeline-title {
font-size: 0.85rem; font-weight: 700; color: var(--text-primary);
display: flex; align-items: center; gap: 6px;
}
.timeline-subtitle {
font-size: 0.7rem; color: var(--text-tertiary);
}
.timeline {
height: 60px; position: relative; background: var(--bg-primary);
border-radius: var(--radius-sm); overflow: hidden;
}
.timeline-hour-markers {
display: flex; justify-content: space-between; padding: 0 4px;
margin-top: 4px;
}
.timeline-hour-marker {
font-size: 0.65rem; color: var(--text-tertiary);
font-variant-numeric: tabular-nums;
}
.timeline-job {
position: absolute; height: 20px; border-radius: 4px;
display: flex; align-items: center; padding: 0 6px; gap: 4px;
font-size: 0.65rem; font-weight: 600; cursor: pointer;
transition: all 0.2s; white-space: nowrap; overflow: hidden;
border: 1px solid transparent;
}
.timeline-job:hover {
transform: translateY(-2px); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
z-index: 10;
}
.timeline-job .emoji { font-size: 0.8rem; }
.timeline-job .name {
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* ── Job Cards ─────────────────────────── */
.jobs-container {
display: flex; flex-direction: column; gap: 10px;
}
.job-card {
background: var(--surface); border: 1px solid var(--border-subtle);
border-radius: var(--radius-md); padding: 14px 16px;
transition: all 0.35s ease; cursor: pointer;
}
.job-card:hover { border-color: var(--border); }
[data-theme="light"] .job-card { box-shadow: var(--shadow-sm); }
.job-card.expanded { border-color: var(--accent); }
.job-header {
display: flex; align-items: center; gap: 12px;
}
.job-agent {
display: flex; align-items: center; gap: 6px;
font-size: 0.85rem; font-weight: 600; color: var(--text-primary);
min-width: 120px;
}
.job-agent .emoji { font-size: 1.2rem; }
.job-main {
flex: 1; display: flex; flex-direction: column; gap: 4px;
}
.job-name {
font-size: 0.9rem; font-weight: 700; color: var(--text-primary);
}
.job-schedule {
font-size: 0.75rem; color: var(--text-secondary);
}
.job-schedule .cron-expr {
font-family: var(--font-mono); background: var(--bg-primary);
padding: 2px 6px; border-radius: 4px; margin-left: 6px;
color: var(--text-tertiary);
}
.job-meta {
display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.job-badge {
display: inline-flex; align-items: center; gap: 4px;
padding: 4px 8px; border-radius: 6px; font-size: 0.7rem; font-weight: 600;
}
.job-badge.enabled {
background: var(--success-bg); color: var(--success);
}
.job-badge.disabled {
background: var(--error-bg); color: var(--error);
}
.job-badge.ok {
background: var(--success-bg); color: var(--success);
}
.job-badge.error {
background: var(--error-bg); color: var(--error);
}
.job-stat {
font-size: 0.72rem; color: var(--text-tertiary);
display: flex; align-items: center; gap: 4px;
}
.job-stat strong {
color: var(--text-secondary); font-weight: 600;
}
.job-details {
margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-subtle);
display: none;
}
.job-card.expanded .job-details {
display: block;
}
.job-detail-section {
margin-bottom: 12px;
}
.job-detail-label {
font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
letter-spacing: 0.06em; color: var(--text-tertiary); margin-bottom: 4px;
}
.job-detail-value {
font-size: 0.8rem; color: var(--text-secondary); line-height: 1.5;
background: var(--bg-primary); padding: 10px 12px;
border-radius: var(--radius-sm); white-space: pre-wrap; word-break: break-word;
}
/* ── Loading State ─────────────────────── */
.loading-state {
text-align: center; padding: 40px 20px; color: var(--text-tertiary);
}
.loading-state .icon { font-size: 2rem; margin-bottom: 12px; opacity: 0.4; }
.loading-state p { font-size: 0.85rem; }
/* ── Empty State ───────────────────────── */
.empty-state {
text-align: center; padding: 40px 20px; color: var(--text-secondary);
}
.empty-state .icon { font-size: 2rem; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 0.85rem; }
/* ── Responsive ────────────────────────── */
@media (max-width: 900px) {
.stats-grid { grid-template-columns: repeat(2, 1fr); }
.job-header { flex-direction: column; align-items: flex-start; }
.job-meta { width: 100%; }
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.fade-up { animation: fadeUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) both; }
/* ── Modal ─────────────────────────────── */
.modal-overlay {
position: fixed; top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0, 0, 0, 0.75); z-index: 1000;
display: none; align-items: center; justify-content: center;
animation: fadeIn 0.2s ease;
}
.modal-overlay.active { display: flex; }
.modal {
background: var(--surface); border: 1px solid var(--border);
border-radius: var(--radius-md); padding: 24px;
max-width: 500px; width: 90%; max-height: 90vh; overflow-y: auto;
animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.modal-header {
display: flex; justify-content: space-between; align-items: center;
margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border-subtle);
}
.modal-title {
font-size: 1.1rem; font-weight: 700; color: var(--text-primary);
}
.modal-close {
padding: 6px; border: none; background: transparent;
color: var(--text-tertiary); cursor: pointer; border-radius: 4px;
display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg-primary); color: var(--text-primary); }
.modal-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label {
font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
letter-spacing: 0.06em; color: var(--text-tertiary);
}
.form-input, .form-select, .form-textarea {
padding: 10px 14px; border-radius: 6px;
background: var(--bg-primary); border: 1px solid var(--border-subtle);
color: var(--text-primary); font-family: var(--font-sans); font-size: 14px;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
border-color: var(--accent); outline: none;
}
.form-textarea { resize: vertical; min-height: 80px; font-family: var(--font-mono); }
.form-hint {
font-size: 0.7rem; color: var(--text-tertiary); margin-top: -2px;
}
.modal-actions {
display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px;
}
.btn {
padding: 10px 18px; font-size: 13px; font-weight: 600;
border-radius: 6px; border: 1px solid var(--border);
cursor: pointer; font-family: var(--font-sans);
transition: all 0.2s ease; display: inline-flex;
align-items: center; gap: 8px;
}
.btn-primary {
background: var(--accent); color: var(--bg-primary); border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
background: var(--surface); color: var(--text-primary);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger {
background: var(--error); color: white; border-color: var(--error);
}
.btn-danger:hover { opacity: 0.9; }
/* ── Delete Button in Job Cards ──────────── */
.job-delete-btn {
padding: 6px 12px; font-size: 12px; font-weight: 600;
border-radius: 4px; border: 1px solid var(--error);
background: transparent; color: var(--error);
cursor: pointer; transition: all 0.2s ease;
display: inline-flex; align-items: center; gap: 4px;
}
.job-delete-btn:hover {
background: var(--error); color: white;
}
/* ── New Cron Button ────────────────────── */
.new-cron-btn {
padding: 10px 18px; font-size: 13px; font-weight: 600;
border-radius: 6px; border: 1px solid var(--accent);
background: var(--accent); color: var(--bg-primary);
cursor: pointer; font-family: var(--font-sans);
transition: all 0.2s ease; display: inline-flex;
align-items: center; gap: 8px; margin-left: auto;
}
.new-cron-btn:hover { background: var(--accent-hover); }
/* ── View Toggle ───────────────────────── */
.view-toggle {
display: flex; gap: 4px; margin-left: auto;
background: var(--bg-primary); border-radius: var(--radius-sm); padding: 3px;
}
.view-toggle-btn {
padding: 6px 12px; border: none; background: transparent;
color: var(--text-secondary); font-size: 0.75rem; font-weight: 600;
border-radius: var(--radius-sm); cursor: pointer;
display: flex; align-items: center; gap: 5px;
transition: all 0.2s ease;
}
.view-toggle-btn:hover { color: var(--text-primary); }
.view-toggle-btn.active {
background: var(--accent); color: var(--bg-primary);
}
/* ── Calendar View ─────────────────────── */
.calendar-container {
background: var(--surface); border: 1px solid var(--border-subtle);
border-radius: var(--radius-md); padding: 16px; margin-bottom: 16px;
}
.calendar-header {
display: flex; justify-content: space-between; align-items: center;
margin-bottom: 16px;
}
.calendar-title {
font-size: 1rem; font-weight: 700; color: var(--text-primary);
}
.calendar-nav {
display: flex; gap: 8px; align-items: center;
}
.calendar-nav-btn {
padding: 6px 10px; border: 1px solid var(--border-subtle);
background: var(--bg-primary); color: var(--text-secondary);
border-radius: var(--radius-sm); cursor: pointer; font-size: 0.8rem;
}
.calendar-nav-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.calendar-grid {
display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
}
.calendar-day-header {
text-align: center; font-size: 0.65rem; font-weight: 700;
color: var(--text-tertiary); padding: 8px 4px;
text-transform: uppercase; letter-spacing: 0.05em;
}
.calendar-day {
min-height: 80px; padding: 6px; border: 1px solid var(--border-subtle);
border-radius: var(--radius-sm); background: var(--bg-primary);
transition: all 0.2s ease; position: relative;
}
.calendar-day:hover { border-color: var(--border); }
.calendar-day.other-month { opacity: 0.4; }
.calendar-day.today { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 5%, var(--bg-primary)); }
.calendar-day-number {
font-size: 0.75rem; font-weight: 600; color: var(--text-secondary);
margin-bottom: 4px;
}
.calendar-day.today .calendar-day-number { color: var(--accent); }
.calendar-day-jobs {
display: flex; flex-direction: column; gap: 2px;
}
.calendar-job {
font-size: 0.6rem; padding: 2px 4px; border-radius: 3px;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
cursor: pointer; transition: transform 0.1s ease;
}
.calendar-job:hover { transform: scale(1.02); }
.calendar-job-count {
font-size: 0.55rem; color: var(--text-tertiary);
margin-top: 2px;
}
</style>
</head>
<body>
<main class="main">
<div class="page-header fade-up" style="display:flex;justify-content:space-between;align-items:flex-start">
<div>
<h1>⏰ Cron Jobs</h1>
<p>Scheduled tasks and automation across all agents</p>
</div>
<button class="new-cron-btn" onclick="openNewCronModal()">
<i data-lucide="plus-circle"></i> New Cron
</button>
</div>
<div class="stats-grid fade-up" style="animation-delay:.05s">
<div class="stat-card">
<div class="stat-label">Total Jobs</div>
<div class="stat-value info" id="statTotalJobs">—</div>
<div class="stat-sub" id="statJobsSub">Loading...</div>
</div>
<div class="stat-card">
<div class="stat-label">Enabled</div>
<div class="stat-value success" id="statEnabledJobs">—</div>
<div class="stat-sub" id="statEnabledSub">Active jobs</div>
</div>
<div class="stat-card">
<div class="stat-label">Agents</div>
<div class="stat-value accent" id="statAgentCount">—</div>
<div class="stat-sub" id="statAgentsSub">With cron jobs</div>
</div>
<div class="stat-card">
<div class="stat-label">Next Run</div>
<div class="stat-value" id="statNextRun">—</div>
<div class="stat-sub" id="statNextRunSub">Upcoming</div>
</div>
</div>
<div class="controls fade-up" style="animation-delay:.1s">
<div class="control-group">
<span class="control-label">Agent</span>
<select class="control-select" id="agentFilter" onchange="applyFilters()">
<option value="all">All Agents</option>
</select>
</div>
<label class="control-checkbox">
<input type="checkbox" id="showDisabled" onchange="applyFilters()" checked>
<span>Show disabled jobs</span>
</label>
<div class="view-toggle">
<button class="view-toggle-btn active" id="viewTimeline" onclick="setView('timeline')">
<i data-lucide="clock" style="width:14px;height:14px"></i> Timeline
</button>
<button class="view-toggle-btn" id="viewCalendar" onclick="setView('calendar')">
<i data-lucide="calendar" style="width:14px;height:14px"></i> Calendar
</button>
</div>
</div>
<div class="timeline-container fade-up" style="animation-delay:.15s" id="timelineContainer">
<div class="timeline-header">
<div class="timeline-title">
<i data-lucide="calendar-clock"></i>
Next 24 Hours
</div>
<div class="timeline-subtitle" id="timelineSubtitle">—</div>
</div>
<div class="timeline" id="timeline"></div>
<div class="timeline-hour-markers" id="timelineMarkers"></div>
</div>
<div class="calendar-container fade-up" style="animation-delay:.15s; display:none" id="calendarContainer">
<div class="calendar-header">
<button class="calendar-nav-btn" onclick="changeMonth(-1)">← Prev</button>
<div class="calendar-title" id="calendarTitle">February 2026</div>
<button class="calendar-nav-btn" onclick="changeMonth(1)">Next →</button>
</div>
<div class="calendar-grid" id="calendarGrid"></div>
</div>
<div class="jobs-container fade-up" style="animation-delay:.2s" id="jobsContainer">
<div class="loading-state">
<div class="icon">⏳</div>
<p>Loading cron jobs...</p>
</div>
</div>
<!-- New Cron Modal -->
<div class="modal-overlay" id="newCronModal" onclick="if(event.target===this) closeNewCronModal()">
<div class="modal">
<div class="modal-header">
<div class="modal-title">Create New Cron Job</div>
<button class="modal-close" onclick="closeNewCronModal()">
<i data-lucide="x" style="width:20px;height:20px"></i>
</button>
</div>
<form class="modal-form" onsubmit="createCron(event)">
<div class="form-group">
<label class="form-label" for="cron-agent">Agent</label>
<select class="form-select" id="cron-agent" required>
<option value="">Select agent...</option>
</select>
</div>
<div class="form-group">
<label class="form-label" for="cron-schedule">Schedule (Cron Expression)</label>
<input type="text" class="form-input" id="cron-schedule" required
placeholder="0 7 * * *">
<div class="form-hint">Examples: "0 7 * * *" (daily at 7am), "*/30 * * * *" (every 30 min)</div>
</div>
<div class="form-group">
<label class="form-label" for="cron-task">Task / Instruction</label>
<textarea class="form-textarea" id="cron-task" required
placeholder="What should the agent do?"></textarea>
</div>
<div class="form-group">
<label class="form-label" for="cron-label">Label (short name)</label>
<input type="text" class="form-input" id="cron-label" required
placeholder="Morning Briefing">
</div>
<div class="modal-actions">
<button type="button" class="btn btn-secondary" onclick="closeNewCronModal()">Cancel</button>
<button type="submit" class="btn btn-primary" id="create-cron-btn">
<i data-lucide="check-circle"></i> Create Job
</button>
</div>
</form>
</div>
</div>
</main>
<script src="/layout.js"></script>
<script>
'use strict';
const $ = s => document.querySelector(s);
let cronData = [];
let filteredJobs = [];
let refreshInterval = null;
// ═══════════════════════════════════════════
// INIT
// ═══════════════════════════════════════════
document.addEventListener('layout:snapshot', () => {
populateAgentFilter();
loadCrons();
});
// Also load immediately — don't wait for SSE snapshot
setTimeout(() => {
if (cronData.length === 0) loadCrons();
}, 500);
// Auto-refresh every 30 seconds
refreshInterval = setInterval(() => {
loadCrons(true); // silent refresh
}, 30000);
function populateAgentFilter() {
const select = $('#agentFilter');
const ids = Object.keys(agentState).sort();
const agentOptions = ids.map(id => {
const a = agentState[id];
return `<option value="${id}">${a.emoji || '🤖'} ${a.name || id}</option>`;
}).join('');
const currentValue = select.value;
select.innerHTML = '<option value="all">All Agents</option>' + agentOptions;
select.value = currentValue; // restore selection
}
// ═══════════════════════════════════════════
// LOAD CRON DATA
// ═══════════════════════════════════════════
async function loadCrons(silent = false) {
try {
const res = await fetch('/api/crons');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const raw = await res.json();
cronData = Array.isArray(raw) ? raw : (raw.jobs || []);
// Enrich with agent info
cronData = cronData.map(job => {
const agentInfo = agentState[job.agentId] || {};
return {
...job,
agentName: agentInfo.name || job.agentId,
agentEmoji: agentInfo.emoji || '🤖',
};
});
applyFilters();
if (!silent) renderAll();
else updateDynamicContent(); // only update time-sensitive parts
} catch (e) {
console.error('Failed to load crons:', e);
if (!silent) {
const container = $('#jobsContainer');
container.innerHTML = `
<div class="empty-state">
<div class="icon">⚠️</div>
<p>Failed to load cron jobs: ${e.message}</p>
</div>
`;
}
}
}
// ═══════════════════════════════════════════
// FILTERS
// ═══════════════════════════════════════════
function applyFilters() {
const agentFilter = $('#agentFilter').value;
const showDisabled = $('#showDisabled').checked;
filteredJobs = cronData.filter(job => {
if (agentFilter !== 'all' && job.agentId !== agentFilter) return false;
if (!showDisabled && !job.enabled) return false;
return true;
});
renderAll();
}
// ═══════════════════════════════════════════
// RENDER
// ═══════════════════════════════════════════
function renderAll() {
renderStats();
renderTimeline();
renderJobs();
refreshIcons();
}
function updateDynamicContent() {
// Update only time-sensitive content (for silent refresh)
updateNextRunTimes();
renderTimeline();
}
function renderStats() {
const total = cronData.length;
const enabled = cronData.filter(j => j.enabled).length;
const agents = new Set(cronData.map(j => j.agentId)).size;
$('#statTotalJobs').textContent = total;
$('#statJobsSub').textContent = `${cronData.length} scheduled`;
$('#statEnabledJobs').textContent = enabled;
$('#statEnabledSub').textContent = `${total - enabled} disabled`;
$('#statAgentCount').textContent = agents;
$('#statAgentsSub').textContent = agents === 1 ? '1 agent' : `${agents} agents`;
// Find next upcoming job
const now = Date.now();
const upcoming = cronData
.filter(j => j.enabled && j.state?.nextRunAtMs && j.state.nextRunAtMs > now)
.sort((a, b) => a.state.nextRunAtMs - b.state.nextRunAtMs);
if (upcoming.length > 0) {
const next = upcoming[0];
$('#statNextRun').textContent = timeAgo(next.state.nextRunAtMs, true);
$('#statNextRunSub').textContent = `${next.agentEmoji} ${next.name}`;
} else {
$('#statNextRun').textContent = '—';
$('#statNextRunSub').textContent = 'No upcoming jobs';
}
}
function renderTimeline() {
const timeline = $('#timeline');
const markers = $('#timelineMarkers');
const subtitle = $('#timelineSubtitle');
const container = $('#timelineContainer');
const now = Date.now();
const end24h = now + 24 * 3600000;
// Get jobs scheduled in next 24h
const upcomingJobs = cronData
.filter(j => j.enabled && j.state?.nextRunAtMs && j.state.nextRunAtMs >= now && j.state.nextRunAtMs <= end24h)
.sort((a, b) => a.state.nextRunAtMs - b.state.nextRunAtMs);
if (upcomingJobs.length === 0) {
container.style.display = 'none';
return;
}
container.style.display = 'block';
subtitle.textContent = `${upcomingJobs.length} job${upcomingJobs.length === 1 ? '' : 's'} scheduled`;
// Clear timeline
timeline.innerHTML = '';
// Generate hour markers (24 hours, show every 3 hours)
markers.innerHTML = '';
for (let i = 0; i <= 24; i += 3) {
const hour = new Date(now + i * 3600000).getHours();
const marker = document.createElement('div');
marker.className = 'timeline-hour-marker';
marker.textContent = `${hour.toString().padStart(2, '0')}:00`;
markers.appendChild(marker);
}
// Colors for agents
const agentColors = generateAgentColors(upcomingJobs);
// Plot jobs on timeline
let lastY = 5; // vertical stacking
upcomingJobs.forEach((job, idx) => {
const timeOffset = job.state.nextRunAtMs - now;
const leftPercent = (timeOffset / (24 * 3600000)) * 100;
const jobEl = document.createElement('div');
jobEl.className = 'timeline-job';
jobEl.style.left = `${leftPercent}%`;
jobEl.style.top = `${lastY}px`;
jobEl.style.background = agentColors[job.agentId] || 'var(--accent)';
jobEl.style.color = 'var(--bg-primary)';
jobEl.innerHTML = `
<span class="emoji">${job.agentEmoji}</span>
<span class="name">${truncate(job.name, 15)}</span>
`;
jobEl.title = `${job.agentName}: ${job.name} at ${new Date(job.state.nextRunAtMs).toLocaleTimeString()}`;
jobEl.onclick = () => scrollToJob(job.id);
timeline.appendChild(jobEl);
// Stagger vertically to avoid overlap
lastY += 25;
if (lastY > 35) lastY = 5;
});
}
function renderJobs() {
const container = $('#jobsContainer');
if (filteredJobs.length === 0) {
container.innerHTML = `
<div class="empty-state">
<div class="icon">📭</div>
<p>No cron jobs found</p>
</div>
`;
return;
}
// Sort: enabled first, then by next run time
const sorted = [...filteredJobs].sort((a, b) => {
if (a.enabled !== b.enabled) return b.enabled - a.enabled;
if (a.state?.nextRunAtMs && b.state?.nextRunAtMs) {
return a.state.nextRunAtMs - b.state.nextRunAtMs;
}
return 0;
});
container.innerHTML = sorted.map(job => {
const schedule = cronToHuman(job.schedule?.expr || '');
const nextRun = job.state?.nextRunAtMs ? timeAgo(job.state.nextRunAtMs, true) : '—';
const lastRun = job.state?.lastRunAtMs ? timeAgo(job.state.lastRunAtMs) : 'Never';
const lastStatus = job.state?.lastStatus || 'unknown';
const lastDuration = job.state?.lastDurationMs ? formatDuration(job.state.lastDurationMs) : '—';
return `
<div class="job-card" id="job-${job.id}">
<div class="job-header" onclick="toggleJob('${job.id}')">
<div class="job-agent">
<span class="emoji">${job.agentEmoji}</span>
<span>${job.agentName}</span>
</div>
<div class="job-main">
<div class="job-name">${escapeHtml(job.name)}</div>
<div class="job-schedule">
${schedule}
<span class="cron-expr">${job.schedule?.expr || ''}</span>
</div>
</div>
<div class="job-meta">
<span class="job-badge ${job.enabled ? 'enabled' : 'disabled'}">
<i data-lucide="${job.enabled ? 'check-circle' : 'x-circle'}" style="width:12px;height:12px"></i>
${job.enabled ? 'Enabled' : 'Disabled'}
</span>
${job.enabled ? `
<span class="job-stat">
<i data-lucide="clock" style="width:12px;height:12px"></i>
<strong>${nextRun}</strong>
</span>
` : ''}
<span class="job-stat">
<i data-lucide="history" style="width:12px;height:12px"></i>
${lastRun}
</span>
${lastStatus !== 'unknown' ? `
<span class="job-badge ${lastStatus === 'ok' ? 'ok' : 'error'}">
${lastStatus}
</span>
` : ''}
${lastDuration !== '—' ? `
<span class="job-stat">
<i data-lucide="timer" style="width:12px;height:12px"></i>
${lastDuration}
</span>
` : ''}
<button class="job-delete-btn" onclick="event.stopPropagation(); deleteCron('${job.id}', '${escapeHtml(job.name)}')">
<i data-lucide="trash-2" style="width:14px;height:14px"></i> Delete
</button>
</div>
</div>
<div class="job-details">
<div class="job-detail-section">
<div class="job-detail-label">Schedule</div>
<div class="job-detail-value">
Expression: <strong>${job.schedule?.expr || 'N/A'}</strong><br>
Kind: ${job.schedule?.kind || 'unknown'}<br>
${job.state?.nextRunAtMs ? `Next run: <strong>${new Date(job.state.nextRunAtMs).toLocaleString()}</strong>` : ''}
</div>
</div>
${job.payload?.text ? `
<div class="job-detail-section">
<div class="job-detail-label">Instruction</div>
<div class="job-detail-value">${escapeHtml(job.payload.text)}</div>
</div>
` : ''}
<div class="job-detail-section">
<div class="job-detail-label">Job ID</div>
<div class="job-detail-value"><code>${job.id}</code></div>
</div>
</div>
</div>
`;
}).join('');
refreshIcons();
}
function updateNextRunTimes() {
// Update "next run" times without re-rendering entire page
filteredJobs.forEach(job => {
const card = document.getElementById(`job-${job.id}`);
if (!card || !job.enabled || !job.state?.nextRunAtMs) return;
const nextRunEl = card.querySelector('.job-stat strong');
if (nextRunEl) {
nextRunEl.textContent = timeAgo(job.state.nextRunAtMs, true);
}
});
// Also update stat card
const now = Date.now();
const upcoming = cronData
.filter(j => j.enabled && j.state?.nextRunAtMs && j.state.nextRunAtMs > now)
.sort((a, b) => a.state.nextRunAtMs - b.state.nextRunAtMs);
if (upcoming.length > 0) {
const next = upcoming[0];
$('#statNextRun').textContent = timeAgo(next.state.nextRunAtMs, true);
}
}
function toggleJob(jobId) {
const card = document.getElementById(`job-${jobId}`);
if (card) {
card.classList.toggle('expanded');
refreshIcons();
}
}
function scrollToJob(jobId) {
const card = document.getElementById(`job-${jobId}`);
if (card) {
card.scrollIntoView({ behavior: 'smooth', block: 'center' });
card.classList.add('expanded');
setTimeout(() => refreshIcons(), 100);
}
}
// ═══════════════════════════════════════════
// CRON EXPRESSION TO HUMAN READABLE
// ═══════════════════════════════════════════
function cronToHuman(expr) {
if (!expr) return 'Unknown schedule';
const parts = expr.split(' ');
if (parts.length < 5) return expr;
const [min, hour, dom, mon, dow] = parts;
// Daily patterns
if (dom === '*' && mon === '*' && dow === '*') {
if (hour !== '*' && min !== '*') {
return `Daily at ${hour.padStart(2, '0')}:${min.padStart(2, '0')}`;
}
}
// Weekly patterns
if (dom === '*' && mon === '*' && dow !== '*' && hour !== '*' && min !== '*') {
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const dayName = days[parseInt(dow)] || `day ${dow}`;
return `${dayName}s at ${hour.padStart(2, '0')}:${min.padStart(2, '0')}`;
}
// Hourly patterns
if (hour === '*' && min !== '*') {
return `Every hour at :${min.padStart(2, '0')}`;
}
// Every N minutes
if (min.startsWith('*/') && hour === '*') {
const interval = min.substring(2);
return `Every ${interval} minutes`;
}
// Fallback to raw expression
return expr;
}
// ═══════════════════════════════════════════
// HELPERS
// ═══════════════════════════════════════════
function timeAgo(ts, future = false) {
const d = ts - Date.now();
const abs = Math.abs(d);
if (abs < 60000) return future ? 'in <1m' : 'just now';
if (abs < 3600000) {
const m = Math.floor(abs / 60000);
return future ? `in ${m}m` : `${m}m ago`;
}
if (abs < 86400000) {
const h = Math.floor(abs / 3600000);
const m = Math.floor((abs % 3600000) / 60000);
return future ? `in ${h}h ${m}m` : `${h}h ago`;
}
const days = Math.floor(abs / 86400000);
return future ? `in ${days}d` : `${days}d ago`;
}
function formatDuration(ms) {
if (ms < 1000) return `${ms}ms`;
if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`;
const m = Math.floor(ms / 60000);
const s = Math.floor((ms % 60000) / 1000);
return `${m}m ${s}s`;
}
function truncate(str, max) {
if (str.length <= max) return str;
return str.slice(0, max - 1) + '…';
}
function escapeHtml(str) {
const div = document.createElement('div');
div.textContent = str;
return div.innerHTML;
}
function generateAgentColors(jobs) {
const agentIds = [...new Set(jobs.map(j => j.agentId))];
const colors = [
'#3b82f6', '#22c55e', '#c9a44a', '#ef4444', '#8b5cf6',
'#f59e0b', '#06b6d4', '#ec4899', '#10b981', '#f97316'
];
const colorMap = {};
agentIds.forEach((id, idx) => {
colorMap[id] = colors[idx % colors.length];
});
return colorMap;
}
// ═══════════════════════════════════════════
// CALENDAR VIEW
// ═══════════════════════════════════════════
let currentView = 'timeline';
let calendarDate = new Date();
function setView(view) {
currentView = view;
$('#viewTimeline').classList.toggle('active', view === 'timeline');
$('#viewCalendar').classList.toggle('active', view === 'calendar');
$('#timelineContainer').style.display = view === 'timeline' ? 'block' : 'none';
$('#calendarContainer').style.display = view === 'calendar' ? 'block' : 'none';
if (view === 'calendar') {
renderCalendar();
}
refreshIcons();
}
function changeMonth(delta) {
calendarDate.setMonth(calendarDate.getMonth() + delta);
renderCalendar();
}
function renderCalendar() {
const grid = $('#calendarGrid');
const title = $('#calendarTitle');
const year = calendarDate.getFullYear();