@milabench/bujang 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState, useMemo, useCallback } from 'react';
2
- import { useParams, useNavigate, Link } from 'react-router-dom';
2
+ import { useParams, useNavigate, Link, useSearchParams } from 'react-router-dom';
3
3
  import { useBujang } from '../context';
4
4
  import { usePageTitle } from '../hooks/usePageTitle';
5
5
  import { Tooltip } from '../components/tooltip';
@@ -16,22 +16,24 @@ import {
16
16
  Badge,
17
17
  Flex,
18
18
  Dialog,
19
- Input,
20
19
  Wrap,
21
20
  WrapItem,
22
- Field,
21
+ SegmentGroup,
23
22
  } from '@chakra-ui/react';
24
23
  import { toaster } from '../toast';
25
- import { LuArrowLeft, LuRefreshCw, LuX, LuDownload, LuInfo, LuExternalLink, LuClock, LuPencil } from 'react-icons/lu';
24
+ import { LuArrowLeft, LuRefreshCw, LuX, LuInfo, LuClock, LuPencil } from 'react-icons/lu';
26
25
  import { useQuery, useQueryClient } from '@tanstack/react-query';
27
- import { getSlurmJobStdoutFull, getSlurmJobStderrFull, getSlurmJobStdoutSize, getSlurmJobStderrSize, getSlurmJobStatusSimple, getSshJobStatus, getSlurmJobAccounting, rerunSlurmJob, cancelSlurmJob, saveSlurmJob, getSlurmJobInfo, getSlurmJobCluster, getSlurmClusterStatus, earlySyncJob, getSlurmJobScript, getSlurmTemplates, getSlurmProfiles } from '../api';
26
+ import { getSlurmJobStdoutFull, getSlurmJobStderrFull, getSlurmJobStdoutSize, getSlurmJobStderrSize, getSlurmJobStatusSimple, getSshJobStatus, getSlurmJobAccounting, rerunSlurmJob, cancelSlurmJob, getSlurmJobInfo, getSlurmJobCluster, getSlurmClusterStatus, earlySyncJob, getSlurmJobScript, getSlurmTemplates, getSlurmProfiles } from '../api';
28
27
  import { JobSubmissionForm } from './JobSubmit';
29
28
  import type { JobSubmissionInitialData } from './JobSubmit';
30
29
  import { LogDisplay } from './LogDisplay';
30
+ import { JobDataOverview } from './JobDataOverview';
31
+ import { JobGroupsButton, JobImportantButton } from './JobMarks';
31
32
  import { NO_JOB_ID } from '../constants';
32
33
  import type { SlurmJobDetail, ApiError } from '../types';
33
34
 
34
35
  type JobLogsViewProps = Record<string, never>;
36
+ type JobLogsTab = 'logs' | 'overview';
35
37
 
36
38
  const getStatusColor = (status: string) => {
37
39
  switch (status?.toLowerCase()) {
@@ -94,8 +96,20 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
94
96
 
95
97
  usePageTitle(`Job Logs - ${slurmJobId || 'Unknown'}`);
96
98
 
99
+ // [Logs | Overview]: kept in the URL (?tab=overview) so the view can be linked
100
+ const [searchParams, setSearchParams] = useSearchParams();
101
+ const activeTab: JobLogsTab = searchParams.get('tab') === 'overview' ? 'overview' : 'logs';
102
+ const setActiveTab = (tab: string) => {
103
+ setSearchParams((params) => {
104
+ const next = new URLSearchParams(params);
105
+ if (tab === 'overview') next.set('tab', 'overview');
106
+ else next.delete('tab');
107
+ return next;
108
+ }, { replace: true });
109
+ };
110
+
97
111
  const navigate = useNavigate();
98
- const { paths, pushJobData } = useBujang();
112
+ const { paths } = useBujang();
99
113
  const queryClient = useQueryClient();
100
114
 
101
115
  // Rerun state
@@ -104,17 +118,6 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
104
118
  // Cancel state
105
119
  const [isCancelling, setIsCancelling] = useState(false);
106
120
 
107
- // Save job state
108
- const [isSaving, setIsSaving] = useState(false);
109
- const [commitMessage, setCommitMessage] = useState('');
110
- const [commitMessageError, setCommitMessageError] = useState('');
111
- const [isSaveModalOpen, setIsSaveModalOpen] = useState(false);
112
- const onSaveModalOpen = () => setIsSaveModalOpen(true);
113
- const onSaveModalClose = () => setIsSaveModalOpen(false);
114
-
115
- // Push data state
116
- const [isPushing, setIsPushing] = useState(false);
117
-
118
121
  // Early sync state
119
122
  const [isEarlySync, setIsEarlySync] = useState(false);
120
123
 
@@ -450,90 +453,6 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
450
453
  }
451
454
  };
452
455
 
453
- const handleSaveClick = () => {
454
- setCommitMessage('');
455
- setCommitMessageError('');
456
- onSaveModalOpen();
457
- };
458
-
459
- const handleSave = async () => {
460
- if (!jrJobId) return;
461
-
462
- // Validate commit message
463
- if (!commitMessage.trim()) {
464
- setCommitMessageError('Commit message is required');
465
- return;
466
- }
467
-
468
- setIsSaving(true);
469
- try {
470
- const result = await saveSlurmJob(jrJobId, commitMessage.trim());
471
-
472
- // Since the API returns an empty object on success, we check for the absence of error
473
- if (!result.error) {
474
- toaster.create({
475
- title: 'Job Saved Successfully',
476
- description: `Job ${jrJobId} has been saved with commit message: "${commitMessage.trim()}"`,
477
- type: 'success',
478
- duration: 5000,
479
- });
480
-
481
- onSaveModalClose();
482
- setCommitMessage('');
483
- } else {
484
- toaster.create({
485
- title: 'Save Failed',
486
- description: result.error || 'Failed to save job',
487
- type: 'error',
488
- duration: 5000,
489
- });
490
- }
491
- } catch (error) {
492
- toaster.create({
493
- title: 'Save Failed',
494
- description: (error as ApiError).message || 'An unexpected error occurred',
495
- type: 'error',
496
- duration: 5000,
497
- });
498
- } finally {
499
- setIsSaving(false);
500
- }
501
- };
502
-
503
- const handlePushData = async () => {
504
- if (!jrJobId || !pushJobData) return;
505
-
506
- setIsPushing(true);
507
- try {
508
- const result = await pushJobData(jrJobId);
509
-
510
- if (result.status === 'OK') {
511
- toaster.create({
512
- title: 'Data Pushed Successfully',
513
- description: `Job data for ${jrJobId} has been pushed successfully.`,
514
- type: 'success',
515
- duration: 5000,
516
- });
517
- } else {
518
- toaster.create({
519
- title: 'Push Failed',
520
- description: 'Failed to push job data',
521
- type: 'error',
522
- duration: 5000,
523
- });
524
- }
525
- } catch (error) {
526
- toaster.create({
527
- title: 'Push Failed',
528
- description: (error as ApiError).message || 'An unexpected error occurred',
529
- type: 'error',
530
- duration: 5000,
531
- });
532
- } finally {
533
- setIsPushing(false);
534
- }
535
- };
536
-
537
456
  const handleEarlySync = async () => {
538
457
  if (!jrJobId || !slurmJobId || slurmJobId === '-') {
539
458
  toaster.create({
@@ -659,6 +578,23 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
659
578
  <HStack justify="space-between">
660
579
  <HStack gap={3}>
661
580
  <Heading size="lg" mb={2}>Job Logs</Heading>
581
+ <SegmentGroup.Root
582
+ size="md"
583
+ mb={2}
584
+ ml={3}
585
+ p={1}
586
+ gap={1}
587
+ value={activeTab}
588
+ onValueChange={(details) => details.value && setActiveTab(details.value)}
589
+ >
590
+ <SegmentGroup.Indicator />
591
+ <SegmentGroup.Items
592
+ items={[{ value: 'logs', label: 'Logs' }, { value: 'overview', label: 'Overview' }]}
593
+ px={5}
594
+ minW="96px"
595
+ justifyContent="center"
596
+ />
597
+ </SegmentGroup.Root>
662
598
  {clusterStatus?.status === 'offline' && (
663
599
  <Tooltip
664
600
  content={`Logs may be stale - cluster is offline${clusterStatus.reason ? `: ${clusterStatus.reason}` : ''}`}
@@ -720,17 +656,6 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
720
656
  <LuClock />
721
657
  Early Sync
722
658
  </Button>
723
- {pushJobData && (
724
- <Button
725
- variant="outline"
726
- colorScheme="blue"
727
- onClick={handlePushData}
728
- loading={isPushing}
729
- disabled={!isJobTerminal}
730
- > <LuExternalLink />
731
- Push Data
732
- </Button>
733
- )}
734
659
  {canCancelJob(jobStatus) && (
735
660
  <Button
736
661
  variant="outline"
@@ -742,15 +667,8 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
742
667
  Cancel Job
743
668
  </Button>
744
669
  )}
745
- <Button
746
- variant="outline"
747
- colorScheme="purple"
748
- onClick={handleSaveClick}
749
- loading={isSaving}
750
- >
751
- <LuDownload />
752
- Save Job
753
- </Button>
670
+ {jrJobId && <JobImportantButton jrJobId={jrJobId} />}
671
+ {jrJobId && <JobGroupsButton jrJobId={jrJobId} />}
754
672
  <Button
755
673
  asChild
756
674
  variant="outline"
@@ -868,7 +786,13 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
868
786
  </Card.Root>
869
787
 
870
788
  {/* Logs Display - the logs are local files, show them even when the status could not be fetched */}
871
- {(jobStatus || !statusLoading) && (
789
+ {activeTab === 'overview' && jrJobId && (
790
+ <Box flex="1" minH={0} overflowY="auto">
791
+ <JobDataOverview jrJobId={jrJobId} />
792
+ </Box>
793
+ )}
794
+
795
+ {activeTab === 'logs' && (jobStatus || !statusLoading) && (
872
796
  <Flex gap={6} direction={{ base: 'column', lg: 'row' }} className="log-holder" flex="1" minH={0} display="flex">
873
797
  <LogDisplay
874
798
  logType="stdout"
@@ -891,7 +815,7 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
891
815
  )}
892
816
 
893
817
  {/* Loading state for logs */}
894
- {!jobStatus && statusLoading && (
818
+ {activeTab === 'logs' && !jobStatus && statusLoading && (
895
819
  <Card.Root bg="var(--color-bg-card)" border="1px solid" borderColor="var(--color-border)" flex="1">
896
820
  <Card.Body>
897
821
  <VStack gap={4} justify="center" h="100%">
@@ -916,45 +840,6 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
916
840
  )}
917
841
  </VStack>
918
842
 
919
- {/* Save Job Modal */}
920
- <Dialog.Root open={isSaveModalOpen} onOpenChange={(details) => setIsSaveModalOpen(details.open)}>
921
- <Dialog.Backdrop />
922
- <Dialog.Positioner>
923
- <Dialog.Content>
924
- <Dialog.Header>
925
- <Dialog.Title>Save Job</Dialog.Title>
926
- <Dialog.CloseTrigger />
927
- </Dialog.Header>
928
- <Dialog.Body>
929
- <VStack align="stretch" gap={4}>
930
- <Field.Root invalid={!!commitMessageError}>
931
- <Field.Label>Commit Message</Field.Label>
932
- <Input
933
- value={commitMessage}
934
- onChange={(e) => setCommitMessage(e.target.value)}
935
- placeholder="Enter a commit message for this job"
936
- onKeyDown={(e) => {
937
- if (e.key === 'Enter' && !isSaving && commitMessage.trim()) {
938
- handleSave();
939
- }
940
- }}
941
- />
942
- <Field.ErrorText>{commitMessageError}</Field.ErrorText>
943
- </Field.Root>
944
- </VStack>
945
- </Dialog.Body>
946
- <Dialog.Footer>
947
- <Button variant="outline" mr={3} onClick={onSaveModalClose}>
948
- Cancel
949
- </Button>
950
- <Button colorScheme="blue" onClick={handleSave} loading={isSaving}>
951
- Save Job
952
- </Button>
953
- </Dialog.Footer>
954
- </Dialog.Content>
955
- </Dialog.Positioner>
956
- </Dialog.Root>
957
-
958
843
  {/* Edit & Resubmit Modal */}
959
844
  <Dialog.Root
960
845
  open={isEditModalOpen}
@@ -0,0 +1,233 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Badge, Box, Button, Dialog, Field, HStack, Input, Text, VStack, Wrap } from '@chakra-ui/react';
3
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
4
+ import { LuFolderPlus, LuGitCommitHorizontal, LuStar } from 'react-icons/lu';
5
+ import { getJobMarks, saveSlurmJob, setJobMarks } from '../api';
6
+ import type { ApiError, JobMarks } from '../types';
7
+ import { toaster } from '../toast';
8
+
9
+ const marksKey = (jrJobId: string) => ['bujang-job-marks', jrJobId];
10
+
11
+ /** Same rule as the server (safe_segment): one folder name */
12
+ const groupName = (value: string) => value.trim().replace(/[^A-Za-z0-9._@+=,-]/g, '_').replace(/^[._]+|[._]+$/g, '');
13
+
14
+ /** The marks of a job, and their update (the job lists and the organizer filters follow) */
15
+ const useJobMarks = (jrJobId: string) => {
16
+ const queryClient = useQueryClient();
17
+ const query = useQuery<JobMarks, ApiError>({
18
+ queryKey: marksKey(jrJobId),
19
+ queryFn: () => getJobMarks(jrJobId),
20
+ enabled: !!jrJobId,
21
+ retry: false,
22
+ });
23
+ const mutation = useMutation<JobMarks, ApiError, { important?: boolean; groups?: string[] }>({
24
+ mutationFn: (marks) => setJobMarks(jrJobId, marks),
25
+ onSuccess: (marks) => {
26
+ queryClient.setQueryData(marksKey(jrJobId), marks);
27
+ queryClient.invalidateQueries({ queryKey: ['slurm-persisted-jobs'] });
28
+ queryClient.invalidateQueries({ queryKey: ['bujang-organizers'] });
29
+ },
30
+ onError: (error) => {
31
+ toaster.create({ title: 'Could not update the job', description: error.message, type: 'error', duration: 5000 });
32
+ },
33
+ });
34
+ return { marks: query.data, isLoading: query.isLoading, update: mutation.mutate, isUpdating: mutation.isPending };
35
+ };
36
+
37
+ /** Star toggle: mark the job important (kept in its meta folder, shown on the jobs page) */
38
+ export const JobImportantButton: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
39
+ const { marks, update, isUpdating } = useJobMarks(jrJobId);
40
+ const important = !!marks?.important;
41
+ return (
42
+ <Button
43
+ variant={important ? 'solid' : 'outline'}
44
+ colorPalette="yellow"
45
+ onClick={() => update({ important: !important })}
46
+ loading={isUpdating}
47
+ disabled={!marks}
48
+ title={important ? 'Important: click to unmark' : 'Mark this job important'}
49
+ >
50
+ <LuStar fill={important ? 'currentColor' : 'none'} />
51
+ {important ? 'Important' : 'Mark Important'}
52
+ </Button>
53
+ );
54
+ };
55
+
56
+ /**
57
+ * "Groups" button and its dialog: add the job to existing groups or a new one
58
+ * (groups/<group>/<job id>), and commit the job folder when the local cache is a git repository.
59
+ */
60
+ export const JobGroupsButton: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
61
+ const { marks, update, isUpdating } = useJobMarks(jrJobId);
62
+ const [open, setOpen] = useState(false);
63
+ const [selected, setSelected] = useState<string[]>([]);
64
+ const [newGroup, setNewGroup] = useState('');
65
+ const [message, setMessage] = useState('');
66
+ const [committing, setCommitting] = useState(false);
67
+
68
+ useEffect(() => {
69
+ if (open && marks) {
70
+ setSelected(marks.groups);
71
+ setNewGroup('');
72
+ setMessage('');
73
+ }
74
+ }, [open, marks]);
75
+
76
+ const known = Object.keys(marks?.all_groups || {});
77
+ const choices = [...new Set([...known, ...selected])].sort();
78
+ const toggle = (name: string) =>
79
+ setSelected((current) => (current.includes(name) ? current.filter((g) => g !== name) : [...current, name]));
80
+ const addNew = () => {
81
+ const name = groupName(newGroup);
82
+ if (!name) return;
83
+ if (!selected.includes(name)) setSelected([...selected, name]);
84
+ setNewGroup('');
85
+ };
86
+
87
+ const save = () => {
88
+ // a name typed but not added yet counts too
89
+ const pending = groupName(newGroup);
90
+ const groups = pending && !selected.includes(pending) ? [...selected, pending] : selected;
91
+ update({ groups }, { onSuccess: () => setOpen(false) });
92
+ };
93
+
94
+ const commit = async () => {
95
+ if (!message.trim()) return;
96
+ setCommitting(true);
97
+ try {
98
+ const result = await saveSlurmJob(jrJobId, message.trim());
99
+ if (result.error) throw new Error(result.error);
100
+ toaster.create({ title: 'Job committed', description: `${jrJobId}: "${message.trim()}"`, type: 'success', duration: 5000 });
101
+ setMessage('');
102
+ } catch (error) {
103
+ toaster.create({ title: 'Commit failed', description: (error as Error).message, type: 'error', duration: 5000 });
104
+ } finally {
105
+ setCommitting(false);
106
+ }
107
+ };
108
+
109
+ const count = marks?.groups.length || 0;
110
+ return (
111
+ <>
112
+ <Button variant="outline" colorPalette="purple" onClick={() => setOpen(true)} disabled={!marks} title="Add the job to groups">
113
+ <LuFolderPlus />
114
+ Groups{count ? ` (${count})` : ''}
115
+ </Button>
116
+ <Dialog.Root open={open} onOpenChange={(details) => setOpen(details.open)}>
117
+ <Dialog.Backdrop />
118
+ <Dialog.Positioner>
119
+ <Dialog.Content>
120
+ <Dialog.Header>
121
+ <Dialog.Title>Groups of this job</Dialog.Title>
122
+ <Dialog.CloseTrigger />
123
+ </Dialog.Header>
124
+ <Dialog.Body>
125
+ <VStack align="stretch" gap={4}>
126
+ <Text fontSize="sm" color="var(--color-text-muted)">
127
+ A job can be in several groups. The jobs page filters by group, and
128
+ the local cache links the job under <code>groups/&lt;group&gt;/</code>.
129
+ </Text>
130
+ {choices.length > 0 ? (
131
+ <Wrap gap={2}>
132
+ {choices.map((name) => {
133
+ const on = selected.includes(name);
134
+ return (
135
+ <Button
136
+ key={name}
137
+ size="sm"
138
+ variant={on ? 'solid' : 'outline'}
139
+ colorPalette="purple"
140
+ onClick={() => toggle(name)}
141
+ >
142
+ {name}
143
+ {!!marks?.all_groups[name] && (
144
+ <Badge size="xs" variant="subtle" title="jobs in this group">{marks.all_groups[name]}</Badge>
145
+ )}
146
+ </Button>
147
+ );
148
+ })}
149
+ </Wrap>
150
+ ) : (
151
+ <Text fontSize="sm">No group yet: create the first one.</Text>
152
+ )}
153
+ <Field.Root>
154
+ <Field.Label>New group</Field.Label>
155
+ <HStack w="100%">
156
+ <Input
157
+ value={newGroup}
158
+ onChange={(e) => setNewGroup(e.target.value)}
159
+ placeholder="baselines, b200-tuning, ..."
160
+ onKeyDown={(e) => { if (e.key === 'Enter') addNew(); }}
161
+ />
162
+ <Button variant="outline" onClick={addNew} disabled={!groupName(newGroup)}>Add</Button>
163
+ </HStack>
164
+ {newGroup && groupName(newGroup) !== newGroup.trim() && (
165
+ <Field.HelperText>Saved as <code>{groupName(newGroup)}</code></Field.HelperText>
166
+ )}
167
+ </Field.Root>
168
+
169
+ {marks?.git && (
170
+ <Box borderTop="1px solid" borderColor="var(--color-border)" pt={4}>
171
+ <Field.Root>
172
+ <Field.Label>Commit the job folder (git)</Field.Label>
173
+ <HStack w="100%">
174
+ <Input
175
+ value={message}
176
+ onChange={(e) => setMessage(e.target.value)}
177
+ placeholder="Commit message"
178
+ onKeyDown={(e) => { if (e.key === 'Enter') commit(); }}
179
+ />
180
+ <Button variant="outline" onClick={commit} loading={committing} disabled={!message.trim()}>
181
+ <LuGitCommitHorizontal /> Commit
182
+ </Button>
183
+ </HStack>
184
+ </Field.Root>
185
+ </Box>
186
+ )}
187
+ </VStack>
188
+ </Dialog.Body>
189
+ <Dialog.Footer>
190
+ <Button variant="outline" mr={3} onClick={() => setOpen(false)}>Cancel</Button>
191
+ <Button colorPalette="purple" onClick={save} loading={isUpdating}>Save groups</Button>
192
+ </Dialog.Footer>
193
+ </Dialog.Content>
194
+ </Dialog.Positioner>
195
+ </Dialog.Root>
196
+ </>
197
+ );
198
+ };
199
+
200
+ /** Star of a job in a list: click to toggle */
201
+ export const JobImportantStar: React.FC<{ jrJobId: string; important: boolean }> = ({ jrJobId, important }) => {
202
+ const queryClient = useQueryClient();
203
+ const [busy, setBusy] = useState(false);
204
+ const toggle = async (e: React.MouseEvent) => {
205
+ e.preventDefault();
206
+ e.stopPropagation();
207
+ setBusy(true);
208
+ try {
209
+ const marks = await setJobMarks(jrJobId, { important: !important });
210
+ queryClient.setQueryData(marksKey(jrJobId), marks);
211
+ await queryClient.invalidateQueries({ queryKey: ['slurm-persisted-jobs'] });
212
+ } catch (error) {
213
+ toaster.create({ title: 'Could not update the job', description: (error as Error).message, type: 'error', duration: 5000 });
214
+ } finally {
215
+ setBusy(false);
216
+ }
217
+ };
218
+ return (
219
+ <Box
220
+ as="button"
221
+ onClick={toggle}
222
+ opacity={busy ? 0.5 : important ? 1 : 0.35}
223
+ _hover={{ opacity: 1 }}
224
+ color={important ? 'yellow.500' : 'var(--color-text-muted)'}
225
+ title={important ? 'Important: click to unmark' : 'Mark important'}
226
+ aria-label={important ? 'Unmark important' : 'Mark important'}
227
+ display="inline-flex"
228
+ verticalAlign="middle"
229
+ >
230
+ <LuStar fill={important ? 'currentColor' : 'none'} />
231
+ </Box>
232
+ );
233
+ };
@@ -575,10 +575,10 @@ export const JobSubmissionForm: React.FC<JobSubmissionFormProps> = ({
575
575
  return;
576
576
  }
577
577
 
578
- // No initialData: apply the selection of the URL, else the form defaults, once
579
- // profiles/templates are available.
580
- const defaultProfile = urlSelection.profile ?? (urlSelection.cluster ? '' : '1x8xA100l');
581
- const defaultTemplate = urlSelection.template ?? 'shared_run.sh';
578
+ // No initialData: apply the profile / template the URL selects, once they are loaded.
579
+ // No URL selection: nothing is preselected.
580
+ const defaultProfile = urlSelection.profile ?? '';
581
+ const defaultTemplate = urlSelection.template ?? '';
582
582
 
583
583
  if (!defaultProfileApplied.current && clusterProfiles.some(p => p.name === defaultProfile) && !selectedProfile) {
584
584
  handleProfileSelect(defaultProfile);