@skyhook-io/radar-app 1.22.1 → 1.22.2

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.
Files changed (46) hide show
  1. package/package.json +1 -1
  2. package/src/App.tsx +96 -28
  3. package/src/RadarApp.tsx +5 -0
  4. package/src/api/client.ts +6 -1
  5. package/src/api/workloadSource.test.tsx +857 -0
  6. package/src/api/workloadSource.ts +292 -0
  7. package/src/components/APIUnreachableBanner.test.tsx +19 -0
  8. package/src/components/APIUnreachableBanner.tsx +20 -0
  9. package/src/components/ConnectionErrorView.test.tsx +63 -2
  10. package/src/components/ConnectionErrorView.tsx +88 -68
  11. package/src/components/diagnose/ActivityTurn.tsx +6 -4
  12. package/src/components/diagnose/AssessmentCard.tsx +1 -2
  13. package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
  14. package/src/components/diagnose/Home.test.tsx +6 -0
  15. package/src/components/diagnose/Home.tsx +10 -3
  16. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
  17. package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
  18. package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
  19. package/src/components/diagnose/InvestigationView.tsx +120 -23
  20. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  21. package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
  22. package/src/components/diagnose/investigationState.ts +9 -0
  23. package/src/components/diagnose/parts.test.tsx +11 -3
  24. package/src/components/diagnose/toolCallLabel.ts +3 -0
  25. package/src/components/home/ActivitySummary.tsx +3 -8
  26. package/src/components/home/ClusterHealthCard.tsx +91 -17
  27. package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
  28. package/src/components/home/HomeView.tsx +6 -26
  29. package/src/components/home/TopologyPreview.test.tsx +31 -30
  30. package/src/components/home/TopologyPreview.tsx +19 -28
  31. package/src/components/home/mcpToolCatalog.ts +3 -3
  32. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
  33. package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
  34. package/src/components/resources/renderers/WorkloadRenderer.tsx +4 -1
  35. package/src/components/workload/WorkloadView.tsx +67 -1
  36. package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
  37. package/src/context/ConnectionContext.tsx +24 -5
  38. package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
  39. package/src/context/ConnectionProvider.handover.test.tsx +94 -0
  40. package/src/context/DiagnoseCustomization.tsx +20 -2
  41. package/src/hooks/useEventSource.test.tsx +275 -4
  42. package/src/hooks/useEventSource.ts +278 -51
  43. package/src/index.ts +1 -0
  44. package/src/utils/navigation.test.ts +1 -6
  45. package/src/utils/navigation.ts +9 -44
  46. package/src/utils/network-policy-navigation.test.ts +21 -36
@@ -88,6 +88,7 @@ import {
88
88
  type RunSummary,
89
89
  } from "../../api/diagnose";
90
90
  import { useDiagnose } from "./DiagnoseContext";
91
+ import { useDiagnoseCustomization } from "../../context/DiagnoseCustomization";
91
92
  import {
92
93
  ExampleInvestigationProvider,
93
94
  replayExampleInvestigation,
@@ -267,6 +268,22 @@ export function InvestigationStatusCheckNotice({
267
268
  );
268
269
  }
269
270
 
271
+ function focusFindingsSection(
272
+ scroller: HTMLElement,
273
+ section: HTMLElement,
274
+ behavior: ScrollBehavior,
275
+ ) {
276
+ section.focus({ preventScroll: true });
277
+ scroller.scrollTo({
278
+ top:
279
+ scroller.scrollTop +
280
+ section.getBoundingClientRect().top -
281
+ scroller.getBoundingClientRect().top -
282
+ 12,
283
+ behavior,
284
+ });
285
+ }
286
+
270
287
  function captureEvidenceCardLayout(container: HTMLElement) {
271
288
  const containerTop = container.getBoundingClientRect().top;
272
289
  return new Map(
@@ -357,6 +374,7 @@ export function InvestigationView({
357
374
  onHandoffAllowedChange?: (allowed: boolean) => void;
358
375
  }) {
359
376
  const { kind, namespace, name } = run;
377
+ const { renderFindingsFooter } = useDiagnoseCustomization();
360
378
  const {
361
379
  refreshRuns,
362
380
  openInvestigation,
@@ -454,6 +472,9 @@ export function InvestigationView({
454
472
  const evidenceScrollTopRef = useRef(0);
455
473
  const evidenceContentRef = useRef<HTMLDivElement>(null);
456
474
  const nextStepsRef = useRef<HTMLElement>(null);
475
+ const assessmentRef = useRef<HTMLElement>(null);
476
+ const composerRef = useRef<HTMLTextAreaElement>(null);
477
+ const [focusTarget, setFocusTarget] = useState<HTMLElement | null>(null);
457
478
  const evidenceCardLayoutRef = useRef(
458
479
  new Map<string, { top: number; height: number }>(),
459
480
  );
@@ -925,6 +946,10 @@ export function InvestigationView({
925
946
  const readOnly = unavailable || !canContinue;
926
947
  const endedEarly = investigationEndedBeforeConclusion(run.status, lastTurn);
927
948
  const rebuildingReplay = !streamReady && turns.length === 0;
949
+ // Mount a host footer after replay so inserting the restored Findings above
950
+ // it cannot move a deep-link landing. A permanent history error is settled.
951
+ const findingsSettled =
952
+ !rebuildingReplay || (historyUnavailable && !historyUnavailable.retryable);
928
953
  const historyUnavailablePresentation = historyUnavailable
929
954
  ? investigationHistoryUnavailablePresentation(historyUnavailable)
930
955
  : null;
@@ -936,6 +961,8 @@ export function InvestigationView({
936
961
  verificationPending,
937
962
  });
938
963
 
964
+ const canAskQuestion = !example && !canStop && !interactionsBlocked;
965
+
939
966
  const submitFollowup = () => {
940
967
  const q = input.trim();
941
968
  if (!q || interactionsBlocked) return;
@@ -1488,15 +1515,22 @@ export function InvestigationView({
1488
1515
  (domId: string, evidence: boolean) => {
1489
1516
  requestAnimationFrame(() => {
1490
1517
  requestAnimationFrame(() => {
1491
- const marker = document.getElementById(domId);
1518
+ const container = evidence
1519
+ ? evidenceScrollRef.current
1520
+ : scrollRef.current;
1521
+ const marker =
1522
+ (evidence && container
1523
+ ? Array.from(
1524
+ container.querySelectorAll<HTMLElement>(
1525
+ `[id="${domId.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"]`,
1526
+ ),
1527
+ ).find((candidate) => !candidate.closest("[inert]"))
1528
+ : undefined) ?? document.getElementById(domId);
1492
1529
  const target = evidence
1493
1530
  ? ((marker?.closest(
1494
1531
  "[data-evidence-card], [data-evidence-source-container]",
1495
1532
  ) as HTMLElement | null) ?? marker)
1496
1533
  : marker;
1497
- const container = evidence
1498
- ? evidenceScrollRef.current
1499
- : scrollRef.current;
1500
1534
  if (target && container) {
1501
1535
  const containerRect = container.getBoundingClientRect();
1502
1536
  const targetRect = target.getBoundingClientRect();
@@ -1559,6 +1593,38 @@ export function InvestigationView({
1559
1593
  [focusAfterPaneSwitch],
1560
1594
  );
1561
1595
 
1596
+ const evidenceLink = useCallback(
1597
+ (ref: string) => {
1598
+ // A proposed change can cite an earlier turn. Resolve exactly one
1599
+ // complete read across this run, even after a newer assessment arrives.
1600
+ const [link] = resolveInvestigationRootCauseEvidence(
1601
+ projection,
1602
+ { status: "linked", refs: [ref] },
1603
+ turns.length - 1,
1604
+ ).links;
1605
+ if (!link) return undefined;
1606
+ const source = link.source;
1607
+ // A grouped Findings card opens its latest read. Older citations should
1608
+ // open their own saved payload, including when both reads look alike.
1609
+ const currentCard = projection.groups.some(
1610
+ (group) =>
1611
+ group.id === link.originalGroupId &&
1612
+ visibleEvidenceGroupIds.has(group.id) &&
1613
+ group.latest.source.id === source.id,
1614
+ );
1615
+ return currentCard
1616
+ ? () => viewEvidenceSource(source.id)
1617
+ : () => viewActivitySource(source.id);
1618
+ },
1619
+ [
1620
+ projection,
1621
+ turns.length,
1622
+ visibleEvidenceGroupIds,
1623
+ viewEvidenceSource,
1624
+ viewActivitySource,
1625
+ ],
1626
+ );
1627
+
1562
1628
  const verificationRunning = turns.some(
1563
1629
  (turn) => turn.verify && turn.status === "running",
1564
1630
  );
@@ -1806,6 +1872,33 @@ export function InvestigationView({
1806
1872
  setUnreadEvidence(false);
1807
1873
  }
1808
1874
  };
1875
+ // An external link can resolve its card while Findings is hidden. Select
1876
+ // the pane first, then position and focus in its post-commit layout.
1877
+ const revealInFindings = useCallback((element: HTMLElement) => {
1878
+ paneSelectionTouchedRef.current = true;
1879
+ setNarrowPane("evidence");
1880
+ setUnreadEvidence(false);
1881
+ setFocusTarget(element);
1882
+ }, []);
1883
+ const viewAssessment = useCallback(() => {
1884
+ if (assessmentRef.current) revealInFindings(assessmentRef.current);
1885
+ }, [revealInFindings]);
1886
+ const askQuestion = useCallback(() => {
1887
+ if (!composerRef.current || composerRef.current.disabled) return;
1888
+ paneSelectionTouchedRef.current = true;
1889
+ setNarrowPane("activity");
1890
+ setFocusTarget(composerRef.current);
1891
+ }, []);
1892
+ useLayoutEffect(() => {
1893
+ if (!focusTarget) return;
1894
+ const scroller = evidenceScrollRef.current;
1895
+ if (scroller?.contains(focusTarget)) {
1896
+ focusFindingsSection(scroller, focusTarget, "instant");
1897
+ } else if (focusTarget === composerRef.current) {
1898
+ focusTarget.focus({ preventScroll: true });
1899
+ }
1900
+ setFocusTarget(null);
1901
+ }, [focusTarget]);
1809
1902
  const viewActivity = () => {
1810
1903
  paneSelectionTouchedRef.current = true;
1811
1904
  setNarrowPane("activity");
@@ -1896,6 +1989,7 @@ export function InvestigationView({
1896
1989
  ) : (
1897
1990
  <div className="flex items-end gap-2">
1898
1991
  <textarea
1992
+ ref={composerRef}
1899
1993
  value={input}
1900
1994
  onChange={(event) => setInput(event.target.value)}
1901
1995
  onKeyDown={(event) => {
@@ -1905,13 +1999,7 @@ export function InvestigationView({
1905
1999
  }
1906
2000
  }}
1907
2001
  rows={1}
1908
- disabled={
1909
- !streamReady ||
1910
- readOnly ||
1911
- busy ||
1912
- requestPending ||
1913
- verificationPending
1914
- }
2002
+ disabled={!canAskQuestion}
1915
2003
  placeholder={
1916
2004
  !streamReady
1917
2005
  ? historyUnavailablePresentation?.loading
@@ -2506,6 +2594,9 @@ export function InvestigationView({
2506
2594
  <div
2507
2595
  ref={evidenceScrollRef}
2508
2596
  data-investigation-findings-scroll
2597
+ // A linked footer can reserve one visible pane of scroll room so a
2598
+ // short card's heading also lands at the top, above its controls.
2599
+ style={renderFindingsFooter ? { containerType: "size" } : undefined}
2509
2600
  onScroll={(event) => {
2510
2601
  if (event.currentTarget.offsetParent === null) return;
2511
2602
  evidenceScrollTopRef.current = event.currentTarget.scrollTop;
@@ -2547,8 +2638,10 @@ export function InvestigationView({
2547
2638
  not a fifth, and it fills the pane it is given. */}
2548
2639
  <div className="space-y-3">
2549
2640
  <section
2641
+ ref={assessmentRef}
2642
+ tabIndex={-1}
2550
2643
  aria-labelledby={`${viewId}-assessment-heading`}
2551
- className="investigation-assessment rounded-xl border p-3"
2644
+ className="investigation-assessment rounded-xl border p-3 outline-none focus-visible:ring-2 focus-visible:ring-accent/50"
2552
2645
  >
2553
2646
  <div className="flex flex-wrap items-center gap-1.5">
2554
2647
  {/* A label for the block, not its headline: the
@@ -2633,17 +2726,11 @@ export function InvestigationView({
2633
2726
  const section = nextStepsRef.current;
2634
2727
  const scroller = evidenceScrollRef.current;
2635
2728
  if (!section || !scroller) return;
2636
- section.focus({ preventScroll: true });
2637
- scroller.scrollTo({
2638
- top:
2639
- scroller.scrollTop +
2640
- section.getBoundingClientRect().top -
2641
- scroller.getBoundingClientRect().top -
2642
- 12,
2643
- behavior: prefersReducedMotion()
2644
- ? "auto"
2645
- : "smooth",
2646
- });
2729
+ focusFindingsSection(
2730
+ scroller,
2731
+ section,
2732
+ prefersReducedMotion() ? "auto" : "smooth",
2733
+ );
2647
2734
  }}
2648
2735
  />
2649
2736
  ) : null
@@ -2805,6 +2892,16 @@ export function InvestigationView({
2805
2892
  />
2806
2893
  </div>
2807
2894
  )}
2895
+ {!example && !gone && findingsSettled &&
2896
+ renderFindingsFooter?.({
2897
+ run,
2898
+ revealInFindings,
2899
+ evidenceLink,
2900
+ viewAssessment: currentAssessment?.diagnosis
2901
+ ? viewAssessment
2902
+ : undefined,
2903
+ askQuestion: canAskQuestion ? askQuestion : undefined,
2904
+ })}
2808
2905
  </div>
2809
2906
  </div>
2810
2907
  </section>
@@ -446,7 +446,7 @@ describe("root-cause evidence resolution", () => {
446
446
  it("keeps an unadapted successful Radar check linkable to Activity", () => {
447
447
  const ref = evidenceRef("a", "b");
448
448
  const projection = project([
449
- tool("metrics-1", "get_dashboard", { result: [1] }, { evidenceRef: ref }),
449
+ tool("metrics-1", "get_cluster_overview", { result: [1] }, { evidenceRef: ref }),
450
450
  ]);
451
451
 
452
452
  expect(projection.groups).toHaveLength(0);
@@ -1831,7 +1831,7 @@ describe("strict evidence adapters", () => {
1831
1831
 
1832
1832
  it("keeps unknown tools in Activity and limits invalid known contracts", () => {
1833
1833
  const result = project([
1834
- tool("other", "get_dashboard", { data: "ignored" }),
1834
+ tool("other", "get_cluster_overview", { data: "ignored" }),
1835
1835
  tool("bad-events", "get_events", { events: [{ nope: true }] }),
1836
1836
  ]);
1837
1837
  expect(result.sources.map((source) => source.stepId)).toEqual([
@@ -780,6 +780,12 @@ export function investigationPaneCenteredScrollTop({
780
780
  return Math.max(0, Math.min(centered, contentHeight - viewportHeight));
781
781
  }
782
782
 
783
+ /** A hosted private run opened through a proposal assignment. The reviewer
784
+ * may decide that proposal, but cannot operate the investigator's session. */
785
+ export function isPrivateRunReviewer(run: RunSummary): boolean {
786
+ return run.visibility === "private" && run.ownedByMe === false;
787
+ }
788
+
783
789
  export function canStopInvestigation(
784
790
  run: RunSummary,
785
791
  busy: boolean,
@@ -791,6 +797,7 @@ export function canStopInvestigation(
791
797
  const transcriptTerminal =
792
798
  latestTurnStatus === "done" || latestTurnStatus === "error";
793
799
  return (
800
+ !isPrivateRunReviewer(run) &&
794
801
  run.trigger !== "background" &&
795
802
  run.status !== "stale" &&
796
803
  run.status !== "stopping" &&
@@ -817,6 +824,7 @@ export function canContinueInOwnAgent(input: {
817
824
  const transcriptTerminal =
818
825
  latestTurnStatus === "done" || latestTurnStatus === "error";
819
826
  return (
827
+ !isPrivateRunReviewer(run) &&
820
828
  input.streamReady &&
821
829
  !input.busy &&
822
830
  !input.requestPending &&
@@ -841,6 +849,7 @@ export function canContinueInvestigation(
841
849
  transcriptTerminal;
842
850
  return (
843
851
  !gone &&
852
+ !isPrivateRunReviewer(run) &&
844
853
  run.status !== "stale" &&
845
854
  run.status !== "stopping" &&
846
855
  (run.canContinue !== false || summaryIsLaggingTerminalTranscript)
@@ -1516,15 +1516,23 @@ describe("TurnView tool outcome truth", () => {
1516
1516
  expect(html).not.toContain("animate-result-in");
1517
1517
  });
1518
1518
 
1519
- it("frames automatic verification as system activity, not user chat", () => {
1519
+ it("describes a workload verification without assuming who started it", () => {
1520
1520
  const verification = turn(false);
1521
1521
  verification.question = "internal verification prompt";
1522
1522
  verification.verify = true;
1523
1523
 
1524
1524
  const html = renderToStaticMarkup(<TurnView turn={verification} />);
1525
- expect(html).toContain("Automatic verification");
1526
- expect(html).toContain("Re-checking after apply");
1525
+ expect(html).toContain("Workload verification");
1526
+ expect(html).toContain("Checking the current workload");
1527
1527
  expect(html).not.toContain("internal verification prompt");
1528
+
1529
+ for (const status of ["done", "error"] as const) {
1530
+ const settled = renderToStaticMarkup(
1531
+ <TurnView turn={{ ...verification, status }} />,
1532
+ );
1533
+ expect(settled).toContain("Workload verification");
1534
+ expect(settled).not.toContain("Checking the current workload");
1535
+ }
1528
1536
  });
1529
1537
 
1530
1538
  it("renders an unknown apply prominently and offers current-state verification", () => {
@@ -62,6 +62,9 @@ export function describeToolCall(tool: string, args?: string): string {
62
62
  : "Looking up packages";
63
63
  case "top_resources":
64
64
  return "Ranking resources";
65
+ case "get_cluster_overview":
66
+ return "Reading the cluster overview";
67
+ // Saved runs, and Radars older than get_cluster_overview, still name it.
65
68
  case "get_dashboard":
66
69
  return "Reading the cluster dashboard";
67
70
  case "get_cluster_audit":
@@ -4,14 +4,12 @@ import { Clock, ArrowRight, Shield } from 'lucide-react'
4
4
  import { useChanges } from '../../api/client'
5
5
  import { isChangeEvent } from '../../types'
6
6
  import type { TimelineEvent } from '../../types'
7
- import type { Topology } from '../../types'
8
7
  import { useHasLimitedAccess } from '../../contexts/CapabilitiesContext'
9
8
  import { buildResourceHierarchy, isProblematicEvent, type ResourceLane } from '../../utils/resource-hierarchy'
10
9
  import { buildHealthSpans, timeToX } from '../timeline/shared'
11
10
 
12
11
  interface ActivitySummaryProps {
13
12
  namespaces: string[]
14
- topology?: Topology | null
15
13
  onNavigate: () => void
16
14
  }
17
15
 
@@ -73,7 +71,7 @@ const KIND_SHORT: Record<string, string> = {
73
71
  TLSRoute: 'TLS',
74
72
  }
75
73
 
76
- export function ActivitySummary({ namespaces, topology, onNavigate }: ActivitySummaryProps) {
74
+ export function ActivitySummary({ namespaces, onNavigate }: ActivitySummaryProps) {
77
75
  const hasLimitedAccess = useHasLimitedAccess()
78
76
  const { data: events, isLoading, error } = useChanges({
79
77
  namespaces,
@@ -100,14 +98,11 @@ export function ActivitySummary({ namespaces, topology, onNavigate }: ActivitySu
100
98
  })
101
99
  if (windowEvents.length === 0) return []
102
100
 
103
- const hierarchy = buildResourceHierarchy({
104
- events: windowEvents,
105
- topology: topology || undefined,
106
- })
101
+ const hierarchy = buildResourceHierarchy({ events: windowEvents })
107
102
  return hierarchy
108
103
  .sort((a, b) => scoreLane(b) - scoreLane(a))
109
104
  .slice(0, MAX_LANES)
110
- }, [events, startTime, now, topology])
105
+ }, [events, startTime, now])
111
106
 
112
107
  const hasActivity = lanes.length > 0
113
108
 
@@ -1,5 +1,6 @@
1
1
  import type { ReactNode } from 'react'
2
2
  import type { DashboardResponse, DashboardMetrics, DashboardCRDCount } from '../../api/client'
3
+ import type { ReadNameSet } from '@skyhook-io/k8s-ui/types/read-coverage'
3
4
  import { HealthRing } from './HealthRing'
4
5
  import {
5
6
  AlertTriangle, CheckCircle, XCircle,
@@ -10,7 +11,7 @@ import { clsx } from 'clsx'
10
11
  import { formatCPUMillicores, formatMemoryMiB } from '../../utils/format'
11
12
  import { useCapabilitiesContext } from '../../contexts/CapabilitiesContext'
12
13
  import { HomeAgentBlock } from './HomeAgentBlock'
13
- import { assetUrl, pluralize, parseContextName, CertaintyGlyph, MiddleEllipsis } from '@skyhook-io/k8s-ui'
14
+ import { assetUrl, pluralize, parseContextName, CertaintyGlyph, MiddleEllipsis, TruncatedText } from '@skyhook-io/k8s-ui'
14
15
  import { Tooltip } from '../ui/Tooltip'
15
16
  import { mcpEndpointUrl } from '../../api/config'
16
17
  import { parseMajorMinor } from '../../utils/version'
@@ -28,6 +29,7 @@ interface ClusterHealthCardProps {
28
29
  cluster: DashboardResponse['cluster']
29
30
  metrics: DashboardMetrics | null
30
31
  metricsServerAvailable: boolean
32
+ selectedNamespaces?: string[]
31
33
  topCRDs?: DashboardCRDCount[] // Loaded lazily, may be undefined
32
34
  issueCount: number
33
35
  hasCriticalIssues: boolean
@@ -135,6 +137,7 @@ export function ClusterHealthCard({
135
137
  cluster,
136
138
  metrics,
137
139
  metricsServerAvailable,
140
+ selectedNamespaces,
138
141
  topCRDs: _topCRDs,
139
142
  issueCount,
140
143
  hasCriticalIssues,
@@ -228,6 +231,10 @@ export function ClusterHealthCard({
228
231
  const { raw: rawName, location, headline: rawHeadline } = clusterIdentity(cluster)
229
232
  const headlineName = isInCluster ? platformInfo.name : rawHeadline
230
233
 
234
+ const requestsScope = resolveRequestsScope(metrics?.requestsNamespaces, selectedNamespaces)
235
+ const requestsScopeLabel = requestsScope && requestsScope.count > 0 ? formatRequestsScopeLabel(requestsScope) : undefined
236
+ const requestsScopeTooltip = requestsScope ? formatRequestsScopeTooltip(requestsScope) : undefined
237
+
231
238
  return (
232
239
  <div className="rounded-xl bg-theme-surface shadow-theme-sm overflow-hidden">
233
240
  {/* Main health section - three columns; stacked on phones */}
@@ -408,17 +415,26 @@ export function ClusterHealthCard({
408
415
  {metricsServerAvailable && (
409
416
  <ResourceBar
410
417
  label="Used"
418
+ scope={requestsScope ? 'whole cluster' : undefined}
411
419
  used={formatCPUMillicores(metrics.cpu.usageMillis)}
412
420
  total={formatCPUMillicores(metrics.cpu.capacityMillis)}
413
421
  percent={metrics.cpu.usagePercent}
414
422
  />
415
423
  )}
416
- <ResourceBar
417
- label="Requested"
418
- used={formatCPUMillicores(metrics.cpu.requestsMillis)}
419
- total={formatCPUMillicores(metrics.cpu.capacityMillis)}
420
- percent={metrics.cpu.requestPercent}
421
- />
424
+ {requestsScope && requestsScope.count === 0 ? (
425
+ <div className="text-[10px] text-theme-text-tertiary">
426
+ Requested: unavailable (no pods read in this scope)
427
+ </div>
428
+ ) : (
429
+ <ResourceBar
430
+ label="Requested"
431
+ scope={requestsScopeLabel}
432
+ scopeTooltip={requestsScopeTooltip}
433
+ used={formatCPUMillicores(metrics.cpu.requestsMillis)}
434
+ total={formatCPUMillicores(metrics.cpu.capacityMillis)}
435
+ percent={metrics.cpu.requestPercent}
436
+ />
437
+ )}
422
438
  </div>
423
439
  )}
424
440
  {metrics?.memory && (
@@ -430,17 +446,26 @@ export function ClusterHealthCard({
430
446
  {metricsServerAvailable && (
431
447
  <ResourceBar
432
448
  label="Used"
449
+ scope={requestsScope ? 'whole cluster' : undefined}
433
450
  used={formatMemoryMiB(metrics.memory.usageMillis)}
434
451
  total={formatMemoryMiB(metrics.memory.capacityMillis)}
435
452
  percent={metrics.memory.usagePercent}
436
453
  />
437
454
  )}
438
- <ResourceBar
439
- label="Requested"
440
- used={formatMemoryMiB(metrics.memory.requestsMillis)}
441
- total={formatMemoryMiB(metrics.memory.capacityMillis)}
442
- percent={metrics.memory.requestPercent}
443
- />
455
+ {requestsScope && requestsScope.count === 0 ? (
456
+ <div className="text-[10px] text-theme-text-tertiary">
457
+ Requested: unavailable (no pods read in this scope)
458
+ </div>
459
+ ) : (
460
+ <ResourceBar
461
+ label="Requested"
462
+ scope={requestsScopeLabel}
463
+ scopeTooltip={requestsScopeTooltip}
464
+ used={formatMemoryMiB(metrics.memory.requestsMillis)}
465
+ total={formatMemoryMiB(metrics.memory.capacityMillis)}
466
+ percent={metrics.memory.requestPercent}
467
+ />
468
+ )}
444
469
  </div>
445
470
  )}
446
471
  {!metricsServerAvailable && (isRestricted('nodes') ? (
@@ -633,13 +658,45 @@ function RestrictedRing({ label }: { label: string }) {
633
658
  )
634
659
  }
635
660
 
661
+ function resolveRequestsScope(
662
+ serverScope: ReadNameSet | undefined,
663
+ selectedNamespaces?: string[],
664
+ ): ReadNameSet | null {
665
+ if (serverScope) return serverScope
666
+ // An older Radar omits requestsNamespaces; fall back to the picker selection
667
+ // the UI sent so picked namespaces still show their scope.
668
+ if (selectedNamespaces && selectedNamespaces.length > 0) {
669
+ const unique = [...new Set(selectedNamespaces)].sort()
670
+ return { count: unique.length, names: unique }
671
+ }
672
+ return null
673
+ }
674
+
675
+ function formatRequestsScopeLabel(scope: ReadNameSet): string {
676
+ if (scope.count === 1 && scope.names?.length === 1) {
677
+ return `in ${scope.names[0]}`
678
+ }
679
+ return `in ${pluralize(scope.count, 'namespace')}`
680
+ }
681
+
682
+ function formatRequestsScopeTooltip(scope: ReadNameSet): string | undefined {
683
+ if (!scope.names || scope.names.length <= 1) return undefined
684
+ const maxShown = 8
685
+ if (scope.names.length <= maxShown) return scope.names.join(', ')
686
+ return `${scope.names.slice(0, maxShown).join(', ')} and ${scope.count - maxShown} more`
687
+ }
688
+
636
689
  function ResourceBar({
637
690
  label,
691
+ scope,
692
+ scopeTooltip,
638
693
  used,
639
694
  total,
640
695
  percent,
641
696
  }: {
642
697
  label: string
698
+ scope?: string
699
+ scopeTooltip?: string
643
700
  used: string
644
701
  total: string
645
702
  percent: number
@@ -648,10 +705,27 @@ function ResourceBar({
648
705
 
649
706
  return (
650
707
  <div>
651
- <div className="flex justify-between items-baseline mb-0.5">
652
- <span className="text-[10px] text-theme-text-tertiary font-mono">{label}: {used} / {total}</span>
653
- <span className="text-[10px] font-medium text-theme-text-secondary font-mono">{percent}%</span>
654
- </div>
708
+ {scope ? (
709
+ <div className="mb-0.5 space-y-0.5">
710
+ <TruncatedText
711
+ text={`${label} (${scope})`}
712
+ tooltip={scopeTooltip}
713
+ className="text-[10px] text-theme-text-secondary"
714
+ >
715
+ <span>{label}</span>{' '}
716
+ <span className="text-theme-text-tertiary">({scope})</span>
717
+ </TruncatedText>
718
+ <div className="flex justify-between items-baseline">
719
+ <span className="text-[10px] text-theme-text-tertiary font-mono">{used} / {total}</span>
720
+ <span className="text-[10px] font-medium text-theme-text-secondary font-mono">{percent}%</span>
721
+ </div>
722
+ </div>
723
+ ) : (
724
+ <div className="flex justify-between items-baseline mb-0.5">
725
+ <span className="text-[10px] text-theme-text-tertiary font-mono">{label}: {used} / {total}</span>
726
+ <span className="text-[10px] font-medium text-theme-text-secondary font-mono">{percent}%</span>
727
+ </div>
728
+ )}
655
729
  <div className="h-2 bg-theme-border rounded overflow-hidden">
656
730
  <div
657
731
  className={clsx('h-full transition-all', barColor)}