@milabench/bujang 0.1.15 → 0.1.17

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.
@@ -31,6 +31,7 @@ import {
31
31
  LuSettings,
32
32
  LuTerminal,
33
33
  LuTrash2,
34
+ LuTable,
34
35
  } from 'react-icons/lu';
35
36
  import {
36
37
  deleteSlurmSecret,
@@ -53,7 +54,7 @@ import type {
53
54
  SettingsSecrets,
54
55
  SshCheckResult,
55
56
  SshPlan,
56
- SshPluginStatus,
57
+ SshHostMerge, SshPluginStatus,
57
58
  SshSettings,
58
59
  SshTestResponse,
59
60
  } from '../types';
@@ -84,6 +85,7 @@ const Section = LinkableCard;
84
85
  /** The cards of the page, in order: their ids are the URL hashes (/settings#ssh) */
85
86
  const SECTIONS: { id: string; label: string }[] = [
86
87
  { id: 'general', label: 'General' },
88
+ { id: 'display', label: 'Display' },
87
89
  { id: 'ssh', label: 'SSH' },
88
90
  { id: 'secrets', label: 'Secrets' },
89
91
  { id: 'folders', label: 'Folders' },
@@ -232,6 +234,43 @@ const GeneralCard: React.FC<{ info: SettingsInfo }> = ({ info }) => {
232
234
  );
233
235
  };
234
236
 
237
+ // ─── Display ────────────────────────────────────────────────────────
238
+
239
+ /** jobs_merged: one table for the active and the persisted jobs on the Jobs page; saved at once */
240
+ export const DisplayCard: React.FC<{ info: SettingsInfo }> = ({ info }) => {
241
+ const queryClient = useQueryClient();
242
+ const field = info.fields.jobs_merged;
243
+ const editable = info.writable && !!info.user_file.path && !field.overridden;
244
+ const save = useMutation({
245
+ mutationFn: (value: boolean) => updateSettings({ jobs_merged: value }),
246
+ onSuccess: (out) => queryClient.setQueryData(SETTINGS_KEY, out.settings),
247
+ onError: fail('Could not save jobs_merged'),
248
+ });
249
+ return (
250
+ <Section id="display" icon={<LuTable />} title="Display" subtitle="Saved to the user file, applies now.">
251
+ <Field.Root>
252
+ <HStack justify="space-between" w="100%" wrap="wrap" gap={2}>
253
+ <Checkbox.Root
254
+ checked={field.value !== false}
255
+ disabled={!editable || save.isPending}
256
+ onCheckedChange={(e) => save.mutate(!!e.checked)}
257
+ >
258
+ <Checkbox.HiddenInput />
259
+ <Checkbox.Control />
260
+ <Checkbox.Label color="var(--color-text)" fontSize="sm">
261
+ One table for the active and the persisted jobs (jobs_merged)
262
+ </Checkbox.Label>
263
+ </Checkbox.Root>
264
+ <FieldBadges field={field} />
265
+ </HStack>
266
+ <Field.HelperText color="var(--color-text-muted)">
267
+ Jobs page. Unchecked: a table for the active jobs and one for the persisted jobs.
268
+ </Field.HelperText>
269
+ </Field.Root>
270
+ </Section>
271
+ );
272
+ };
273
+
235
274
  // ─── Folders ────────────────────────────────────────────────────────
236
275
 
237
276
  /** show_examples: list the example scripts and pipelines (built-in, *_example*); saved at once */
@@ -542,16 +581,49 @@ const DiffView: React.FC<{ diff: string }> = ({ diff }) => (
542
581
  </Box>
543
582
  );
544
583
 
584
+ /** The hosts of a plugin the user has entries for: whose options are used (the user's win) */
585
+ const HostMerges: React.FC<{ hosts: SshHostMerge[]; plugin: string }> = ({ hosts, plugin }) => {
586
+ const merged = hosts.filter(h => h.source !== null && Object.keys(h.yours).length > 0);
587
+ if (!merged.length) return null;
588
+ const options = (values: Record<string, string>) =>
589
+ Object.entries(values).map(([key, value]) => `${key} ${value}`).join(', ') || '—';
590
+ return (
591
+ <Box overflowX="auto">
592
+ <Text fontSize="sm" color="var(--color-text)" mb={1}>
593
+ Merged with your own entries, which win and are not changed:
594
+ </Text>
595
+ <Table.Root size="sm" variant="outline">
596
+ <Table.Header>
597
+ <Table.Row>
598
+ {['Host', 'Yours', `From ${plugin}`].map(h => <Table.ColumnHeader key={h}>{h}</Table.ColumnHeader>)}
599
+ </Table.Row>
600
+ </Table.Header>
601
+ <Table.Body>
602
+ {merged.map(h => (
603
+ <Table.Row key={h.alias}>
604
+ <Table.Cell fontFamily="mono" fontSize="xs">
605
+ {h.alias}{h.source !== h.alias && <Text color="var(--color-text-muted)">your Host {h.source}</Text>}
606
+ </Table.Cell>
607
+ <Table.Cell fontFamily="mono" fontSize="xs">{options(h.yours)}</Table.Cell>
608
+ <Table.Cell fontFamily="mono" fontSize="xs" color="var(--color-text-muted)">{options(h.plugin)}</Table.Cell>
609
+ </Table.Row>
610
+ ))}
611
+ </Table.Body>
612
+ </Table.Root>
613
+ </Box>
614
+ );
615
+ };
616
+
545
617
  const PluginBlock: React.FC<{
546
618
  plugin: SshPluginStatus;
547
619
  file: string;
548
620
  writable: boolean;
549
621
  onChanged: () => void;
550
622
  }> = ({ plugin, file, writable, onChanged }) => {
551
- const [values, setValues] = useState<Record<string, string>>(plugin.values);
623
+ const [values, setValues] = useState<Record<string, string>>({ ...plugin.inferred, ...plugin.values });
552
624
  const [dedupe, setDedupe] = useState(false);
553
625
  const [plan, setPlan] = useState<SshPlan | null>(null);
554
- useEffect(() => { setValues(plugin.values); setPlan(null); }, [plugin, file]);
626
+ useEffect(() => { setValues({ ...plugin.inferred, ...plugin.values }); setPlan(null); }, [plugin, file]);
555
627
 
556
628
  const request = (action: 'install' | 'remove') => ({
557
629
  file,
@@ -605,18 +677,7 @@ const PluginBlock: React.FC<{
605
677
  {plugin.duplicates} more bujang:{plugin.name} block(s) in the file: dedupe removes them.
606
678
  </Text>
607
679
  )}
608
- {plugin.conflicts.length > 0 && (
609
- <Box>
610
- <Text fontSize="sm" color="var(--color-text)">
611
- Entries outside the block define the same hosts; ssh uses the first value it finds:
612
- </Text>
613
- {plugin.conflicts.map(c => (
614
- <Text key={`${c.line}-${c.alias}`} fontSize="xs" fontFamily="mono" color="var(--color-text-muted)">
615
- line {c.line}: {c.text}
616
- </Text>
617
- ))}
618
- </Box>
619
- )}
680
+ <HostMerges hosts={plan?.action === 'install' ? plan.hosts : plugin.hosts} plugin={plugin.name} />
620
681
 
621
682
  {plugin.placeholders.length > 0 && (
622
683
  <Grid templateColumns={{ base: '1fr', md: 'repeat(2, minmax(0, 1fr))' }} gap={3}>
@@ -636,15 +697,15 @@ const PluginBlock: React.FC<{
636
697
  </Grid>
637
698
  )}
638
699
 
639
- <HStack gap={3} wrap="wrap">
700
+ {plugin.duplicates > 0 && <HStack gap={3} wrap="wrap">
640
701
  <Checkbox.Root checked={dedupe} onCheckedChange={(e) => { setDedupe(!!e.checked); setPlan(null); }}>
641
702
  <Checkbox.HiddenInput />
642
703
  <Checkbox.Control />
643
704
  <Checkbox.Label color="var(--color-text)" fontSize="sm">
644
- Dedupe: drop the older Host entries for these hosts
705
+ Dedupe: drop the other copies of the block
645
706
  </Checkbox.Label>
646
707
  </Checkbox.Root>
647
- </HStack>
708
+ </HStack>}
648
709
 
649
710
  <HStack gap={2} wrap="wrap">
650
711
  <Button size="sm" colorPalette="blue" variant="outline" disabled={missing.length > 0}
@@ -1090,6 +1151,7 @@ export const SettingsView: React.FC = () => {
1090
1151
  <VStack align="stretch" gap={6}>
1091
1152
  {!info.writable && <ReadOnlyNote reason={info.read_only_reason} />}
1092
1153
  <GeneralCard info={info} />
1154
+ <DisplayCard info={info} />
1093
1155
  <SshCard info={info} />
1094
1156
  <SecretsCard writable={info.writable} />
1095
1157
  <FoldersCard info={info} />
@@ -1,7 +1,7 @@
1
1
  /** Charts of the JSONL data of a job: the chart builder, its Vega-Lite spec, and the chart itself. */
2
2
  import React, { useEffect, useRef, useState } from 'react';
3
3
  import { Alert, Box } from '@chakra-ui/react';
4
- import type { JobData, JobDataField, JobDataRole, OverviewPanel } from '../types';
4
+ import type { JobData, JobDataField, JobDataRole, OverviewBlock } from '../types';
5
5
  import { useColorMode } from '../hooks/useColorMode';
6
6
 
7
7
  /** Rows fetched for a chart (the server caps at 500k) */
@@ -15,7 +15,7 @@ export const MARKS = ['point', 'line', 'bar', 'tick', 'boxplot', 'area', 'rect']
15
15
  export const AGGREGATES = ['', 'mean', 'median', 'sum', 'min', 'max', 'count'] as const;
16
16
  /** Events listed first: the plotted ones (the server gives each event its role) */
17
17
  export const ROLE_ORDER: Record<JobDataRole, number> = { metric: 0, other: 1, log: 2 };
18
- /** The keys of a `bujang.logs` line around its data: never a category of a chart */
18
+ /** The keys of a `bujang.instrumentation` line around its data: never a category of a chart */
19
19
  export const ENVELOPE_FIELDS = new Set(['type', 'event', 'level', 'logger', 'message', 'exception']);
20
20
 
21
21
  export interface Builder {
@@ -175,7 +175,8 @@ export const VegaChart: React.FC<{ spec: Record<string, unknown>; rows: Record<s
175
175
  }, [spec, rows, colorMode]);
176
176
 
177
177
  return (
178
- <Box w="100%" minH="340px">
178
+ // room for the chart while it loads
179
+ <Box w="100%" minH={`${Math.min(typeof spec.height === 'number' ? spec.height + 20 : spec.height ? 100 : 340, 340)}px`}>
179
180
  {error && (
180
181
  <Alert.Root status="error" mb={2}>
181
182
  <Alert.Indicator />
@@ -190,15 +191,46 @@ export const VegaChart: React.FC<{ spec: Record<string, unknown>; rows: Record<s
190
191
  );
191
192
  };
192
193
 
193
- /** The files that have rows of `event` */
194
- export const filesWithEvent = (files: JobData['files'], event: string): JobData['files'] =>
195
- files.filter((f) => f.events?.some((e) => e.event === event));
194
+ /** The events of a panel (`event`: comma separated, "" for the records without event) */
195
+ export const panelEvents = (event?: string): string[] => {
196
+ const list = (event || '').split(',').map((e) => e.trim()).filter(Boolean);
197
+ return list.length ? list : [''];
198
+ };
199
+
200
+ /** The files that have rows of `event` (comma separated events) */
201
+ export const filesWithEvent = (files: JobData['files'], event: string): JobData['files'] => {
202
+ const events = panelEvents(event);
203
+ return files.filter((f) => f.events?.some((e) => events.includes(e.event)));
204
+ };
205
+
206
+ /** The rank of the process that wrote a file: its `rank` field, when all its rows have the same one */
207
+ const rankField = (file: JobData['files'][number]): number | null => {
208
+ for (const e of file.events || []) {
209
+ const field = e.fields.find((f) => f.name === 'rank' && f.type === 'number');
210
+ if (field && field.min !== undefined) return field.min === field.max ? field.min : null;
211
+ }
212
+ return null;
213
+ };
214
+
215
+ /** The rank of each file (null: of none). In a job whose files have a `rank`, the others are told by their name, <name>.<rank>.jsonl */
216
+ export const fileRanks = (files: JobData['files']): Map<string, number | null> => {
217
+ const ranks = new Map(files.map((f) => [f.path, rankField(f)]));
218
+ const known = new Set([...ranks.values()].filter((r) => r !== null));
219
+ files.forEach((f) => {
220
+ const named = /\.(\d+)\.jsonl$/.exec(f.path);
221
+ if (ranks.get(f.path) === null && named && known.has(Number(named[1])) && !f.events?.some((e) => e.fields.some((x) => x.name === 'rank'))) {
222
+ ranks.set(f.path, Number(named[1]));
223
+ }
224
+ });
225
+ return ranks;
226
+ };
196
227
 
197
- /** The fields of `event` in `files`, merged (counts added, ranges widened, values joined) */
228
+ /** The fields of `event` (comma separated events) in `files`, merged (counts added, ranges widened, values joined) */
198
229
  export const mergeFields = (files: JobData['files'], event: string): JobDataField[] => {
199
230
  const merged = new Map<string, JobDataField>();
231
+ const events = panelEvents(event);
200
232
  files.forEach((f) =>
201
- f.events?.filter((e) => e.event === event).forEach((e) =>
233
+ f.events?.filter((e) => events.includes(e.event)).forEach((e) =>
202
234
  e.fields.forEach((field) => {
203
235
  const prev = merged.get(field.name);
204
236
  if (!prev) {
@@ -218,7 +250,7 @@ export const mergeFields = (files: JobData['files'], event: string): JobDataFiel
218
250
  };
219
251
 
220
252
  /** The files a panel reads (`files`: comma separated paths or globs, all when empty) */
221
- export const panelFiles = (files: JobData['files'], patterns?: string): JobData['files'] => {
253
+ export const panelFiles = <T extends { path: string }, >(files: T[], patterns?: string): T[] => {
222
254
  const wanted = (patterns || '').split(',').map((p) => p.trim()).filter(Boolean);
223
255
  if (!wanted.length) return files;
224
256
  const glob = (p: string) => new RegExp(`^${p.replace(/[.+^${}()|\\]/g, '\\$&').replace(/\*/g, '[^/]*').replace(/\?/g, '.')}$`);
@@ -226,7 +258,7 @@ export const panelFiles = (files: JobData['files'], patterns?: string): JobData[
226
258
  };
227
259
 
228
260
  /** A chart panel of a layout from the builder (only what differs from the defaults) */
229
- export const panelOfBuilder = (b: Builder, event: string, title?: string): OverviewPanel => ({
261
+ export const panelOfBuilder = (b: Builder, event: string, title?: string): OverviewBlock => ({
230
262
  kind: 'chart',
231
263
  title: title || event || 'records',
232
264
  event,
@@ -243,7 +275,7 @@ export const panelOfBuilder = (b: Builder, event: string, title?: string): Overv
243
275
  });
244
276
 
245
277
  /** The builder of a chart panel; null when the panel gives no field (the page guesses them) */
246
- export const builderOfPanel = (p: Extract<OverviewPanel, { kind: 'chart' }>): Builder | null => {
278
+ export const builderOfPanel = (p: Extract<OverviewBlock, { kind: 'chart' }>): Builder | null => {
247
279
  if (!p.x && !p.y && p.aggregate !== 'count') return null;
248
280
  return {
249
281
  ...EMPTY_BUILDER,