@skyhook-io/radar-app 1.22.0 → 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 (95) hide show
  1. package/package.json +1 -1
  2. package/src/App.tsx +98 -29
  3. package/src/RadarApp.tsx +5 -0
  4. package/src/api/client.ts +18 -1
  5. package/src/api/cnpg-history.ts +3 -3
  6. package/src/api/cnpg-storage.ts +3 -3
  7. package/src/api/diagnose.test.ts +34 -0
  8. package/src/api/diagnose.ts +17 -4
  9. package/src/api/radarFeatures.test.ts +13 -1
  10. package/src/api/radarFeatures.ts +2 -0
  11. package/src/api/resourceActions.test.ts +829 -0
  12. package/src/api/resourceActions.ts +584 -0
  13. package/src/api/resourceActions.ui.test.tsx +1882 -0
  14. package/src/api/reviewedActionMutation.ts +56 -28
  15. package/src/api/substrateHealth.ts +2 -3
  16. package/src/api/traffic.ts +13 -5
  17. package/src/api/workloadMetrics.test.ts +11 -2
  18. package/src/api/workloadMetrics.ts +2 -2
  19. package/src/api/workloadSource.test.tsx +857 -0
  20. package/src/api/workloadSource.ts +292 -0
  21. package/src/components/APIUnreachableBanner.test.tsx +19 -0
  22. package/src/components/APIUnreachableBanner.tsx +20 -0
  23. package/src/components/ConnectionErrorView.test.tsx +63 -2
  24. package/src/components/ConnectionErrorView.tsx +88 -68
  25. package/src/components/diagnose/ActivityTurn.tsx +6 -4
  26. package/src/components/diagnose/AnalysisStory.test.tsx +12 -0
  27. package/src/components/diagnose/AssessmentCard.tsx +1 -2
  28. package/src/components/diagnose/ContinueInAgentButton.test.tsx +7 -0
  29. package/src/components/diagnose/DiagnoseContext.question.test.tsx +34 -1
  30. package/src/components/diagnose/DiagnoseContext.tsx +28 -3
  31. package/src/components/diagnose/DiagnoseSurface.tsx +5 -4
  32. package/src/components/diagnose/Home.test.tsx +6 -0
  33. package/src/components/diagnose/Home.tsx +13 -3
  34. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +1 -1
  35. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +61 -0
  36. package/src/components/diagnose/InvestigationEvidencePane.tsx +19 -2
  37. package/src/components/diagnose/InvestigationFindingsFooter.test.tsx +413 -0
  38. package/src/components/diagnose/InvestigationView.followupFailure.test.tsx +122 -0
  39. package/src/components/diagnose/InvestigationView.tsx +130 -25
  40. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +1 -1
  41. package/src/components/diagnose/LocalDiagnoseAction.tsx +2 -2
  42. package/src/components/diagnose/QuestionComposer.test.tsx +16 -2
  43. package/src/components/diagnose/QuestionComposer.tsx +13 -8
  44. package/src/components/diagnose/diagnoseEvidenceTypes.ts +47 -8
  45. package/src/components/diagnose/investigationEvidence/adapters/diagnose.test.ts +153 -0
  46. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +9 -13
  47. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +21 -5
  48. package/src/components/diagnose/investigationEvidence/bodies/network.tsx +63 -26
  49. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  50. package/src/components/diagnose/investigationEvidence/projection.test.ts +1 -1
  51. package/src/components/diagnose/investigationState.ts +9 -0
  52. package/src/components/diagnose/launch.ts +1 -1
  53. package/src/components/diagnose/parts.test.tsx +11 -3
  54. package/src/components/diagnose/toolCallLabel.ts +3 -0
  55. package/src/components/dock/PodDebugSession.test.tsx +66 -0
  56. package/src/components/dock/PodDebugSession.tsx +3 -1
  57. package/src/components/dock/TerminalTab.test.tsx +43 -3
  58. package/src/components/dock/TerminalTab.tsx +10 -1
  59. package/src/components/helm/HelmReleaseDrawer.tsx +1 -1
  60. package/src/components/helm/InstallWizard.tsx +1 -1
  61. package/src/components/home/ActivitySummary.tsx +3 -8
  62. package/src/components/home/ClusterHealthCard.tsx +91 -17
  63. package/src/components/home/ClusterHealthCard.utilization.test.tsx +187 -0
  64. package/src/components/home/HomeView.tsx +6 -26
  65. package/src/components/home/TopologyPreview.test.tsx +31 -30
  66. package/src/components/home/TopologyPreview.tsx +19 -28
  67. package/src/components/home/mcpToolCatalog.ts +4 -4
  68. package/src/components/resources/PodEvictAction.test.tsx +951 -0
  69. package/src/components/resources/PodEvictAction.tsx +167 -0
  70. package/src/components/resources/ResourcesView.tsx +3 -0
  71. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +5 -4
  72. package/src/components/resources/renderers/RolloutRenderer.tsx +4 -1
  73. package/src/components/resources/renderers/WorkloadRenderer.tsx +7 -1
  74. package/src/components/settings/LocalConnectionSettings.tsx +4 -4
  75. package/src/components/settings/SettingsDialog.tsx +23 -18
  76. package/src/components/settings/integrationQueries.test.ts +98 -0
  77. package/src/components/settings/integrationQueries.ts +36 -0
  78. package/src/components/traffic/TrafficView.reconnect.test.tsx +229 -0
  79. package/src/components/traffic/TrafficView.tsx +91 -35
  80. package/src/components/ui/Markdown.test.tsx +37 -0
  81. package/src/components/ui/Markdown.tsx +15 -2
  82. package/src/components/useContextSwitchFlow.test.tsx +27 -2
  83. package/src/components/useContextSwitchFlow.tsx +20 -22
  84. package/src/components/workload/WorkloadView.tsx +83 -4
  85. package/src/components/workload/WorkloadView.workloadSource.test.tsx +121 -0
  86. package/src/context/ConnectionContext.tsx +24 -5
  87. package/src/context/ConnectionProvider.connectionId.test.tsx +14 -0
  88. package/src/context/ConnectionProvider.handover.test.tsx +94 -0
  89. package/src/context/DiagnoseCustomization.tsx +20 -2
  90. package/src/hooks/useEventSource.test.tsx +275 -4
  91. package/src/hooks/useEventSource.ts +278 -51
  92. package/src/index.ts +1 -0
  93. package/src/utils/navigation.test.ts +1 -6
  94. package/src/utils/navigation.ts +9 -44
  95. 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,
@@ -391,6 +409,7 @@ export function InvestigationView({
391
409
  const [busy, setBusy] = useState(false);
392
410
  const [requestPending, setRequestPending] = useState(false);
393
411
  const explanationRequestSerial = useRef(0);
412
+ const followupRequestSerial = useRef(0);
394
413
  const [explanationRequest, setExplanationRequest] = useState<{
395
414
  sequence: number;
396
415
  status: "running" | "error";
@@ -453,6 +472,9 @@ export function InvestigationView({
453
472
  const evidenceScrollTopRef = useRef(0);
454
473
  const evidenceContentRef = useRef<HTMLDivElement>(null);
455
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);
456
478
  const evidenceCardLayoutRef = useRef(
457
479
  new Map<string, { top: number; height: number }>(),
458
480
  );
@@ -924,6 +946,10 @@ export function InvestigationView({
924
946
  const readOnly = unavailable || !canContinue;
925
947
  const endedEarly = investigationEndedBeforeConclusion(run.status, lastTurn);
926
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);
927
953
  const historyUnavailablePresentation = historyUnavailable
928
954
  ? investigationHistoryUnavailablePresentation(historyUnavailable)
929
955
  : null;
@@ -935,6 +961,8 @@ export function InvestigationView({
935
961
  verificationPending,
936
962
  });
937
963
 
964
+ const canAskQuestion = !example && !canStop && !interactionsBlocked;
965
+
938
966
  const submitFollowup = () => {
939
967
  const q = input.trim();
940
968
  if (!q || interactionsBlocked) return;
@@ -946,9 +974,16 @@ export function InvestigationView({
946
974
  setNarrowPane("activity");
947
975
  suppressEvidenceMotionRef.current = false;
948
976
  pinnedRef.current = true; // a user-initiated turn always follows to the bottom
977
+ const serial = ++followupRequestSerial.current;
949
978
  setRequestPending(true);
950
979
  addTurn(run.id, { question: q }).catch((e) => {
951
980
  setRequestPending(false);
981
+ // Hand the question back so a refusal (too long, say) can be fixed
982
+ // instead of retyped. Only when the server answered with a refusal: a
983
+ // network failure may hide an accepted turn. Not when a newer follow-up
984
+ // was sent since, or the engineer has started typing.
985
+ if (e instanceof DiagnoseError && serial === followupRequestSerial.current)
986
+ setInput((current) => (current === "" ? q : current));
952
987
  setActionError(e instanceof DiagnoseError ? e.message : "Couldn't send.");
953
988
  setActionRefusal(investigationRefusal(e));
954
989
  });
@@ -1480,15 +1515,22 @@ export function InvestigationView({
1480
1515
  (domId: string, evidence: boolean) => {
1481
1516
  requestAnimationFrame(() => {
1482
1517
  requestAnimationFrame(() => {
1483
- 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);
1484
1529
  const target = evidence
1485
1530
  ? ((marker?.closest(
1486
1531
  "[data-evidence-card], [data-evidence-source-container]",
1487
1532
  ) as HTMLElement | null) ?? marker)
1488
1533
  : marker;
1489
- const container = evidence
1490
- ? evidenceScrollRef.current
1491
- : scrollRef.current;
1492
1534
  if (target && container) {
1493
1535
  const containerRect = container.getBoundingClientRect();
1494
1536
  const targetRect = target.getBoundingClientRect();
@@ -1551,6 +1593,38 @@ export function InvestigationView({
1551
1593
  [focusAfterPaneSwitch],
1552
1594
  );
1553
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
+
1554
1628
  const verificationRunning = turns.some(
1555
1629
  (turn) => turn.verify && turn.status === "running",
1556
1630
  );
@@ -1798,6 +1872,33 @@ export function InvestigationView({
1798
1872
  setUnreadEvidence(false);
1799
1873
  }
1800
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]);
1801
1902
  const viewActivity = () => {
1802
1903
  paneSelectionTouchedRef.current = true;
1803
1904
  setNarrowPane("activity");
@@ -1888,6 +1989,7 @@ export function InvestigationView({
1888
1989
  ) : (
1889
1990
  <div className="flex items-end gap-2">
1890
1991
  <textarea
1992
+ ref={composerRef}
1891
1993
  value={input}
1892
1994
  onChange={(event) => setInput(event.target.value)}
1893
1995
  onKeyDown={(event) => {
@@ -1897,13 +1999,7 @@ export function InvestigationView({
1897
1999
  }
1898
2000
  }}
1899
2001
  rows={1}
1900
- disabled={
1901
- !streamReady ||
1902
- readOnly ||
1903
- busy ||
1904
- requestPending ||
1905
- verificationPending
1906
- }
2002
+ disabled={!canAskQuestion}
1907
2003
  placeholder={
1908
2004
  !streamReady
1909
2005
  ? historyUnavailablePresentation?.loading
@@ -2024,8 +2120,8 @@ export function InvestigationView({
2024
2120
  {parseContextName(run.context).clusterName}
2025
2121
  </span>
2026
2122
  </Tooltip>
2027
- . It is read-only because its agent session was closed after a
2028
- cluster switch.
2123
+ . It is read-only because the cluster connection it ran on has
2124
+ closed.
2029
2125
  </span>
2030
2126
  </div>
2031
2127
  ) : null}
@@ -2498,6 +2594,9 @@ export function InvestigationView({
2498
2594
  <div
2499
2595
  ref={evidenceScrollRef}
2500
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}
2501
2600
  onScroll={(event) => {
2502
2601
  if (event.currentTarget.offsetParent === null) return;
2503
2602
  evidenceScrollTopRef.current = event.currentTarget.scrollTop;
@@ -2539,8 +2638,10 @@ export function InvestigationView({
2539
2638
  not a fifth, and it fills the pane it is given. */}
2540
2639
  <div className="space-y-3">
2541
2640
  <section
2641
+ ref={assessmentRef}
2642
+ tabIndex={-1}
2542
2643
  aria-labelledby={`${viewId}-assessment-heading`}
2543
- 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"
2544
2645
  >
2545
2646
  <div className="flex flex-wrap items-center gap-1.5">
2546
2647
  {/* A label for the block, not its headline: the
@@ -2625,17 +2726,11 @@ export function InvestigationView({
2625
2726
  const section = nextStepsRef.current;
2626
2727
  const scroller = evidenceScrollRef.current;
2627
2728
  if (!section || !scroller) return;
2628
- section.focus({ preventScroll: true });
2629
- scroller.scrollTo({
2630
- top:
2631
- scroller.scrollTop +
2632
- section.getBoundingClientRect().top -
2633
- scroller.getBoundingClientRect().top -
2634
- 12,
2635
- behavior: prefersReducedMotion()
2636
- ? "auto"
2637
- : "smooth",
2638
- });
2729
+ focusFindingsSection(
2730
+ scroller,
2731
+ section,
2732
+ prefersReducedMotion() ? "auto" : "smooth",
2733
+ );
2639
2734
  }}
2640
2735
  />
2641
2736
  ) : null
@@ -2797,6 +2892,16 @@ export function InvestigationView({
2797
2892
  />
2798
2893
  </div>
2799
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
+ })}
2800
2905
  </div>
2801
2906
  </div>
2802
2907
  </section>
@@ -37,7 +37,7 @@ vi.mock("../../api/diagnose", async (importOriginal) => ({
37
37
  present: true,
38
38
  supported: true,
39
39
  hosted: api.hosted,
40
- questions: true,
40
+ targetQuestions: true,
41
41
  profiles: ["safeguarded"],
42
42
  consentSurfaces: { safeguarded: "claude:safeguarded" },
43
43
  },
@@ -86,13 +86,13 @@ function DiagnoseResourceButton({
86
86
  : `Ask ${d.agentLabel} about this resource — reads its spec, events & logs.`
87
87
  : problem
88
88
  ? `Investigate with your own ${d.agentLabel} — runs locally and reads this resource's spec, events & logs.`
89
- : d.questions
89
+ : d.targetQuestions
90
90
  ? `Ask your own ${d.agentLabel} a question about this resource — runs locally, reads its spec, events & logs.`
91
91
  : `Ask your own ${d.agentLabel} about this resource — runs locally, reads its spec, events & logs.`;
92
92
  // While an investigation is live, the button advertises it (and clicking focuses
93
93
  // the existing run rather than starting a new one — openInvestigation dedups).
94
94
  const showLabel = problem || running;
95
- const asks = d.questions && !problem && !running;
95
+ const asks = d.targetQuestions && !problem && !running;
96
96
  // Asking about a resource with no live problem means saying what to ask; a
97
97
  // problem, or a run already live, opens straight away.
98
98
  const act = () => {
@@ -75,8 +75,8 @@ afterEach(async () => {
75
75
  document.body.replaceChildren();
76
76
  });
77
77
 
78
- async function render() {
79
- await act(async () => root.render(<QuestionComposer />));
78
+ async function render(requireResource = false) {
79
+ await act(async () => root.render(<QuestionComposer requireResource={requireResource} />));
80
80
  }
81
81
 
82
82
  function textarea() {
@@ -551,3 +551,17 @@ describe("QuestionComposer", () => {
551
551
  expect(document.body.textContent).toContain("Still loading");
552
552
  });
553
553
  });
554
+
555
+ it("requires a resource before starting a target-only question, including Enter after unpinning", async () => {
556
+ state.questionDraft = { seq: 1, pin: { kind: "Deployment", group: "apps", namespace: "shop", name: "checkout" } };
557
+ await render(true);
558
+ await type("Can we scale checkout to five replicas?");
559
+ const submit = document.querySelector<HTMLButtonElement>('button[type="submit"]')!;
560
+ expect(submit.disabled).toBe(false);
561
+ await act(async () => document.querySelector<HTMLButtonElement>('[aria-label="Unpin resource"]')!.click());
562
+ expect(submit.disabled).toBe(true);
563
+ expect(document.body.textContent).toContain("Choose a resource");
564
+ expect(document.body.textContent).not.toContain("Start in");
565
+ await press("Enter");
566
+ expect(state.openInvestigation).not.toHaveBeenCalled();
567
+ });
@@ -53,9 +53,11 @@ const actionClass =
53
53
  export function QuestionComposer({
54
54
  onBrowseIssues,
55
55
  onOpenExample,
56
+ requireResource = false,
56
57
  }: {
57
58
  onBrowseIssues?: () => void;
58
59
  onOpenExample?: () => void;
60
+ requireResource?: boolean;
59
61
  }) {
60
62
  const { openInvestigation, agentLabel, questionDraft, saveQuestionDraft } =
61
63
  useDiagnose();
@@ -74,7 +76,7 @@ export function QuestionComposer({
74
76
  ? { text: questionDraft.text.trim(), askedAt: questionDraft.askedAt }
75
77
  : null,
76
78
  );
77
- const [pickerOpen, setPickerOpen] = useState(!!questionDraft?.pickResource);
79
+ const [pickerOpen, setPickerOpen] = useState(!!questionDraft?.pickResource || (requireResource && !questionDraft?.pin));
78
80
  const textRef = useRef<HTMLTextAreaElement>(null);
79
81
  const pickerInputRef = useRef<HTMLInputElement>(null);
80
82
  // Focus now so typing straight away lands in the box; once new text has
@@ -124,8 +126,8 @@ export function QuestionComposer({
124
126
  (pin
125
127
  ? suggestionsForPin(pinIssues ?? [], pin)
126
128
  : suggestionsFromIssues(issuesData?.issues ?? [])
127
- ).filter((suggestion) => !asked.includes(suggestion.question)),
128
- [pin, pinIssues, issuesData, asked],
129
+ ).filter((suggestion) => (!requireResource || pin || suggestion.pin) && !asked.includes(suggestion.question)),
130
+ [pin, pinIssues, issuesData, asked, requireResource],
129
131
  );
130
132
 
131
133
  useEffect(() => {
@@ -210,8 +212,9 @@ export function QuestionComposer({
210
212
 
211
213
  const question = text.trim();
212
214
  const tooLong = [...question].length > MAX_QUESTION_LENGTH;
215
+ const canSubmit = !!question && !tooLong && (!requireResource || !!pin);
213
216
  const submit = () => {
214
- if (!question || tooLong) return;
217
+ if (!canSubmit) return;
215
218
  submitted.current = true;
216
219
  openInvestigation({
217
220
  fromComposer: true,
@@ -248,7 +251,7 @@ export function QuestionComposer({
248
251
  What are you seeing?
249
252
  </h1>
250
253
  <p className="mt-1 text-sm text-theme-text-tertiary">
251
- Describe a problem, or ask whether something looks right. {agentLabel}{" "}
254
+ {requireResource ? "Choose a resource and describe what you want to investigate or change." : "Describe a problem, or ask whether something looks right."} {agentLabel}{" "}
252
255
  investigates it with Radar’s read-only tools and shows what it found,
253
256
  with the evidence.
254
257
  </p>
@@ -302,7 +305,7 @@ export function QuestionComposer({
302
305
  </span>
303
306
  <button
304
307
  type="button"
305
- onClick={() => setPin(null)}
308
+ onClick={() => { setPin(null); if (requireResource) setPickerOpen(true); }}
306
309
  aria-label="Unpin resource"
307
310
  className="rounded text-theme-text-tertiary hover:text-theme-text-primary"
308
311
  >
@@ -311,6 +314,7 @@ export function QuestionComposer({
311
314
  </span>
312
315
  ) : (
313
316
  <>
317
+ {!requireResource && <>
314
318
  <span className="text-xs text-theme-text-tertiary">Start in</span>
315
319
  {startIn.length === 0 ? (
316
320
  <Tooltip
@@ -357,6 +361,7 @@ export function QuestionComposer({
357
361
  ))}
358
362
  </select>
359
363
  )}
364
+ </>}
360
365
  <button
361
366
  type="button"
362
367
  onClick={() => setPickerOpen((open) => !open)}
@@ -364,7 +369,7 @@ export function QuestionComposer({
364
369
  className={actionClass}
365
370
  >
366
371
  <AtSign className="h-3 w-3" />
367
- Pin a resource
372
+ {requireResource ? "Choose a resource" : "Pin a resource"}
368
373
  </button>
369
374
  </>
370
375
  )}
@@ -395,7 +400,7 @@ export function QuestionComposer({
395
400
  </span>
396
401
  <button
397
402
  type="submit"
398
- disabled={!question || tooLong}
403
+ disabled={!canSubmit}
399
404
  className="btn-brand ml-1 inline-flex items-center gap-1 rounded-md px-2.5 py-1 text-xs font-medium disabled:opacity-50"
400
405
  >
401
406
  Investigate
@@ -142,16 +142,55 @@ export interface DiagnosisChangeContext {
142
142
  evidence?: string;
143
143
  }
144
144
 
145
+ // A rewrite or template rule copied from a stored CoreDNS Corefile. It is what
146
+ // the ConfigMap says, with no verdict.
147
+ export interface DiagnosisCoreDNSRule {
148
+ kind: string;
149
+ namespace: string;
150
+ name: string;
151
+ key: string;
152
+ line: number;
153
+ text: string;
154
+ truncated?: boolean;
155
+ }
156
+
157
+ // A verdict on a CoreDNS ConfigMap, in the `coreDNSFindings` shape. Some Radar
158
+ // versions send it in place of `coreDNSRules`, and Radar Hub shows their
159
+ // clusters with this UI.
160
+ export interface DiagnosisLegacyCoreDNSFinding {
161
+ kind: string;
162
+ namespace: string;
163
+ name: string;
164
+ severity?: string;
165
+ reason?: string;
166
+ message?: string;
167
+ }
168
+
145
169
  export interface DiagnosisDNSContext {
146
170
  signals?: string[];
147
- coreDNSFindings?: Array<{
148
- kind: string;
149
- namespace: string;
150
- name: string;
151
- severity: string;
152
- reason: string;
153
- message?: string;
154
- }>;
171
+ coreDNSRules?: DiagnosisCoreDNSRule[];
172
+ // Stored rules left out of coreDNSRules by the server's cap.
173
+ omittedCoreDNSRules?: number;
174
+ coreDNSFindings?: DiagnosisLegacyCoreDNSFinding[];
175
+ }
176
+
177
+ // The configuration facts Radar sends as DNS signals. Each names a resource, so
178
+ // its text is never searched for failure words: a workload can be called
179
+ // "errors-api".
180
+ const DNS_CONFIGURATION_SIGNAL =
181
+ / uses dnsPolicy=| sets dnsConfig\.|^CoreDNS Deployment |^Radar observed ConfigMap /;
182
+
183
+ // Whether a DNS signal reports a failed lookup, as opposed to a configuration
184
+ // fact such as a pod's dnsPolicy or a CoreDNS rollout.
185
+ export function dnsSignalReportsFailure(signal: string): boolean {
186
+ return (
187
+ !DNS_CONFIGURATION_SIGNAL.test(signal) &&
188
+ /\b(errors?|failed|failures?|timeouts?|nxdomain|servfail)\b/i.test(signal)
189
+ );
190
+ }
191
+
192
+ export function coreDNSRulesSummary(count: number): string {
193
+ return `${count} CoreDNS rule${count === 1 ? "" : "s"}`;
155
194
  }
156
195
 
157
196
  export type DiagnosisEvidenceTone =
@@ -9,7 +9,160 @@ import {
9
9
  warningEvent,
10
10
  } from "../evidenceFixtures";
11
11
 
12
+ const storedRule = {
13
+ kind: "ConfigMap",
14
+ namespace: "kube-system",
15
+ name: "coredns",
16
+ key: "Corefile",
17
+ line: 5,
18
+ text: "rewrite name regex .*\\.nodes\\.vcluster\\.com kubernetes.default.svc.cluster.local",
19
+ };
20
+
21
+ // The `coreDNSFindings` shape: a verdict on the ConfigMap.
22
+ const legacyFinding = {
23
+ kind: "ConfigMap",
24
+ namespace: "kube-system",
25
+ name: "coredns",
26
+ severity: "warning",
27
+ reason: "CoreDNS service DNS rewrite",
28
+ };
29
+
12
30
  describe("semantic diagnose evidence projection", () => {
31
+ // The exact strings the server emits (internal/mcp/tools_diagnose.go,
32
+ // internal/issues/provider.go), and the "errors" wording some versions use. A
33
+ // stored CoreDNS rule is configuration; only these make DNS evidence adverse.
34
+ it.each([
35
+ "pod logs contain DNS resolution failures",
36
+ "warning events contain DNS resolution failures",
37
+ "pod logs contain DNS resolution errors",
38
+ "warning events contain DNS resolution errors",
39
+ ])("treats %j as a DNS failure with or without stored rules", (signal) => {
40
+ for (const coreDNSRules of [undefined, [storedRule]]) {
41
+ const result = project([
42
+ tool("dns-failure", "diagnose", {
43
+ resource: deployment,
44
+ resourceContext: { tier: "basic" },
45
+ pods: 0,
46
+ events: [],
47
+ dnsContext: { signals: [signal], coreDNSRules },
48
+ }),
49
+ ]);
50
+ expect(groupsOf(result.groups, "dns")[0].latest).toMatchObject({
51
+ tone: "warning",
52
+ title: "DNS failure signals",
53
+ });
54
+ }
55
+ });
56
+
57
+ it("keeps stored CoreDNS rules neutral when no lookup failed", () => {
58
+ const result = project([
59
+ tool("dns-config", "diagnose", {
60
+ resource: deployment,
61
+ resourceContext: { tier: "basic" },
62
+ pods: 0,
63
+ events: [],
64
+ dnsContext: {
65
+ signals: ["api uses dnsPolicy=None"],
66
+ coreDNSRules: [storedRule],
67
+ },
68
+ }),
69
+ ]);
70
+ expect(groupsOf(result.groups, "dns")[0].latest).toMatchObject({
71
+ tier: "context",
72
+ tone: "info",
73
+ title: "DNS configuration",
74
+ });
75
+ });
76
+
77
+ // The server's configuration signals, with resource names that contain
78
+ // failure words (internal/mcp/tools_diagnose.go, internal/issues/provider.go).
79
+ it.each([
80
+ "errors-api uses dnsPolicy=None",
81
+ "servfail-exporter sets dnsConfig.nameservers",
82
+ "failed-jobs sets dnsConfig.searches",
83
+ "CoreDNS Deployment kube-system/coredns-errors rolled 2m ago (generation=3, 2 owned ReplicaSets, newest=coredns-errors-abc)",
84
+ "Radar observed ConfigMap kube-system/coredns-failures update 4m ago",
85
+ ])("reads %j as configuration, whatever the resource is called", (signal) => {
86
+ const result = project([
87
+ tool("dns-config-name", "diagnose", {
88
+ resource: deployment,
89
+ resourceContext: { tier: "basic" },
90
+ pods: 0,
91
+ events: [],
92
+ dnsContext: { signals: [signal], coreDNSRules: [storedRule] },
93
+ }),
94
+ ]);
95
+ expect(groupsOf(result.groups, "dns")[0].latest).toMatchObject({
96
+ tone: "info",
97
+ title: "DNS configuration",
98
+ });
99
+ });
100
+
101
+ it("reads the issues DNS context sent under the dns key", () => {
102
+ const result = project([
103
+ tool("issues-dns-legacy", "issues", {
104
+ issues: [],
105
+ total: 0,
106
+ total_matched: 0,
107
+ cluster_context: {
108
+ dns: {
109
+ signals: ["CoreDNS Deployment kube-system/coredns rolled 2m ago"],
110
+ findings: [legacyFinding],
111
+ },
112
+ },
113
+ }),
114
+ ]);
115
+ expect(groupsOf(result.groups, "dns")[0].latest).toMatchObject({
116
+ tone: "info",
117
+ data: { type: "dns", dns: { coreDNSFindings: [legacyFinding] } },
118
+ });
119
+ });
120
+
121
+ it("does not let a CoreDNS verdict make the card adverse", () => {
122
+ const result = project([
123
+ tool("dns-legacy", "diagnose", {
124
+ resource: deployment,
125
+ resourceContext: { tier: "basic" },
126
+ pods: 0,
127
+ events: [],
128
+ dnsContext: { coreDNSFindings: [legacyFinding] },
129
+ }),
130
+ ]);
131
+ expect(groupsOf(result.groups, "dns")[0].latest).toMatchObject({
132
+ tone: "info",
133
+ title: "DNS configuration",
134
+ });
135
+ });
136
+
137
+ it("warns on cluster DNS context only when a lookup failure was seen", () => {
138
+ const tones = [
139
+ "Warning events in namespace shop contain DNS resolution failures",
140
+ "CoreDNS Deployment kube-system/coredns rolled out 2m ago",
141
+ ].map((signal) => {
142
+ const result = project([
143
+ tool("issues-dns", "issues", {
144
+ issues: [],
145
+ total: 0,
146
+ total_matched: 0,
147
+ cluster_context: {
148
+ dns_config: {
149
+ signals: [signal],
150
+ rules: [storedRule],
151
+ omitted_rules: 2,
152
+ },
153
+ },
154
+ }),
155
+ ]);
156
+ const latest = groupsOf(result.groups, "dns")[0].latest;
157
+ expect(latest.data).toMatchObject({
158
+ type: "dns",
159
+ dns: { coreDNSRules: [storedRule], omittedCoreDNSRules: 2 },
160
+ });
161
+ return latest.tone;
162
+ });
163
+ expect(tones).toEqual(["warning", "info"]);
164
+ });
165
+
13
166
  it("promotes only classified smoking guns and audits every partiality signal", () => {
14
167
  const result = project([
15
168
  tool("diagnose-1", "diagnose", {