@skyhook-io/radar-app 1.18.2 → 1.19.0

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 (78) hide show
  1. package/package.json +4 -4
  2. package/src/App.tsx +0 -1
  3. package/src/api/diagnose.test.ts +33 -2
  4. package/src/api/diagnose.ts +93 -3
  5. package/src/api/radarFeatures.ts +1 -0
  6. package/src/components/diagnose/AIMarkdown.tsx +1 -1
  7. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  8. package/src/components/diagnose/AgentControls.tsx +53 -6
  9. package/src/components/diagnose/AgentSetupNotice.tsx +1 -1
  10. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  11. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  12. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  13. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  14. package/src/components/diagnose/AssessmentCard.tsx +39 -8
  15. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  16. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  17. package/src/components/diagnose/DiagnoseContext.tsx +205 -9
  18. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  19. package/src/components/diagnose/DiagnoseSurface.tsx +93 -21
  20. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  21. package/src/components/diagnose/Home.test.tsx +182 -5
  22. package/src/components/diagnose/Home.tsx +168 -36
  23. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  24. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  25. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  26. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
  27. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  28. package/src/components/diagnose/InvestigationEvidenceSections.tsx +5 -1
  29. package/src/components/diagnose/InvestigationView.tsx +156 -29
  30. package/src/components/diagnose/LocalDiagnoseAction.tsx +23 -16
  31. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  32. package/src/components/diagnose/QuestionComposer.tsx +487 -0
  33. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  34. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  35. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  36. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  37. package/src/components/diagnose/assessmentCopy.ts +5 -0
  38. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  39. package/src/components/diagnose/investigationCase.ts +33 -1
  40. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  41. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +8 -0
  42. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  43. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
  44. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
  45. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  46. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  47. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  48. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  49. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  50. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  51. package/src/components/diagnose/investigationEvidence/types.ts +2 -0
  52. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  53. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  54. package/src/components/diagnose/investigationFocus.ts +132 -0
  55. package/src/components/diagnose/parts.test.tsx +20 -0
  56. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  57. package/src/components/diagnose/questionSuggestions.ts +150 -0
  58. package/src/components/diagnose/storyParts.test.tsx +13 -0
  59. package/src/components/diagnose/target.test.ts +143 -2
  60. package/src/components/diagnose/target.ts +109 -7
  61. package/src/components/diagnose/testdata/story-runs.json +474 -0
  62. package/src/components/diagnose/verdictText.test.tsx +87 -0
  63. package/src/components/diagnose/verdictText.ts +68 -0
  64. package/src/components/home/ClusterHealthCard.tsx +13 -39
  65. package/src/components/home/HomeAgentBlock.test.tsx +113 -0
  66. package/src/components/home/HomeAgentBlock.tsx +94 -0
  67. package/src/components/home/HomeView.tsx +5 -6
  68. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  69. package/src/components/home/RadarVersionLine.tsx +3 -28
  70. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  71. package/src/components/ui/Omnibar.tsx +47 -3
  72. package/src/components/ui/RadarOmnibar.test.tsx +1 -0
  73. package/src/components/ui/RadarOmnibar.tsx +11 -0
  74. package/src/components/whats-new/WhatsNewDialog.test.tsx +3 -3
  75. package/src/components/whats-new/releaseNotes.ts +60 -1
  76. package/src/hooks/useAgentSignin.test.tsx +190 -0
  77. package/src/hooks/useAgentSignin.ts +160 -0
  78. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { renderToStaticMarkup } from "react-dom/server";
3
3
  import { deployment, groupsOf, project, tool } from "../evidenceFixtures";
4
+ import { projectInvestigationEvidence } from "../index";
4
5
  import { RankingBody } from "../bodies/ranking";
5
6
  import { PostureBody } from "../bodies/posture";
6
7
  import { InventoryBody, namedInventoryRows } from "../bodies/inventory";
@@ -680,3 +681,48 @@ describe("metric discovery receipt", () => {
680
681
  expect(group.latest.summary).toBe("42 metrics · last hour");
681
682
  });
682
683
  });
684
+
685
+ describe("posture cards in a run with no resource", () => {
686
+ const audit = tool("audit", "get_cluster_audit", {
687
+ findings: [
688
+ {
689
+ resource: "Deployment/other/web",
690
+ check: "noLimits",
691
+ severity: "medium",
692
+ message: "No limits.",
693
+ },
694
+ ],
695
+ totalCount: 1,
696
+ });
697
+ const none = { kind: "", group: "", namespace: "", name: "" };
698
+
699
+ it("keeps every finding as a citable card and says nothing about a resource", () => {
700
+ const projection = projectInvestigationEvidence(
701
+ [{ timeline: [audit] }],
702
+ none,
703
+ );
704
+ const [card] = groupsOf(projection.groups, "posture");
705
+ expect(card.latest.relevance).toBe("broader");
706
+ expect(
707
+ card.latest.data.type === "posture" &&
708
+ card.latest.data.findings.map((finding) => finding.name),
709
+ ).toEqual(["web"]);
710
+ expect(
711
+ groupsOf(projection.groups, "receipt").map((group) => group.latest.title),
712
+ ).not.toContain("No posture findings on this resource");
713
+ });
714
+
715
+ it("files an empty scan without naming a resource", () => {
716
+ const empty = tool("audit", "get_cluster_audit", {
717
+ findings: [],
718
+ totalCount: 0,
719
+ });
720
+ const projection = projectInvestigationEvidence(
721
+ [{ timeline: [empty] }],
722
+ none,
723
+ );
724
+ expect(
725
+ groupsOf(projection.groups, "receipt").map((group) => group.latest.title),
726
+ ).toContain("No posture findings");
727
+ });
728
+ });
@@ -762,6 +762,11 @@ export function adaptDiagnose(
762
762
  name: resource.metadata.name,
763
763
  },
764
764
  bundleRelevance,
765
+ Array.isArray(value.podNames) &&
766
+ value.podNames.every(nonEmptyString) &&
767
+ value.podNamesTruncated !== true
768
+ ? (value.podNames as string[])
769
+ : undefined,
765
770
  );
766
771
  if (value.recentChangesSaturated === true) {
767
772
  builder.limit(
@@ -837,6 +842,8 @@ function addDiagnoseMetrics(
837
842
  raw: unknown,
838
843
  subject: DiagnosisResourceRef,
839
844
  relevance: InvestigationEvidenceRelevance,
845
+ // The bundle's pod list comes from the same pod set its charts sum.
846
+ podNames: string[] | undefined,
840
847
  ): void {
841
848
  if (raw === undefined) return;
842
849
  const value = record(raw);
@@ -907,6 +914,7 @@ function addDiagnoseMetrics(
907
914
  truncated: false,
908
915
  subject,
909
916
  pods: value.pods,
917
+ ...(podNames ? { podNames } : {}),
910
918
  partial,
911
919
  };
912
920
  builder.observe(
@@ -24,7 +24,30 @@ function keep(
24
24
  label: string,
25
25
  ): void {
26
26
  const kept = findings.filter((_, index) => relevances[index] !== "broader");
27
+ const elsewhere = findings.filter(
28
+ (_, index) => relevances[index] === "broader",
29
+ );
27
30
  const scope = scopeFromArgs(source);
31
+ // A run with no resource keeps every finding as one broader card, which the
32
+ // pane withholds unless the agent cites it; without it such a run would
33
+ // have nothing to cite. A run about a resource keeps the receipt alone, so
34
+ // a citation of "nothing here concerns this resource" lands on it.
35
+ const keepElsewhere = () => {
36
+ if (elsewhere.length === 0 || builder.target.name) return;
37
+ builder.observe(
38
+ `posture:${origin}:broader:${source.args ?? scope}`,
39
+ "posture",
40
+ source,
41
+ {
42
+ tier: evidenceTierForRelevance("context", "broader"),
43
+ relevance: "broader",
44
+ tone: "neutral",
45
+ title: label,
46
+ summary: `${elsewhere.length} finding${elsewhere.length === 1 ? "" : "s"} · ${scope}`,
47
+ data: { type: "posture", source: origin, findings: elsewhere, scope },
48
+ },
49
+ );
50
+ };
28
51
  if (missing.length > 0) {
29
52
  builder.limit(
30
53
  source,
@@ -34,7 +57,9 @@ function keep(
34
57
  );
35
58
  }
36
59
  if (kept.length === 0) {
60
+ keepElsewhere();
37
61
  if (!source.confirmedSuccess) return;
62
+ if (!builder.target.name && elsewhere.length > 0) return;
38
63
  builder.observe(
39
64
  `posture:${origin}:receipt:${source.args ?? scope}`,
40
65
  "receipt",
@@ -43,7 +68,9 @@ function keep(
43
68
  tier: evidenceTierForRelevance("checked", "producer-related"),
44
69
  relevance: "producer-related",
45
70
  tone: "neutral",
46
- title: `No ${label.toLowerCase()} on this resource`,
71
+ title: builder.target.name
72
+ ? `No ${label.toLowerCase()} on this resource`
73
+ : `No ${label.toLowerCase()}`,
47
74
  summary: scope,
48
75
  data: {
49
76
  type: "receipt",
@@ -82,6 +109,7 @@ function keep(
82
109
  data: { type: "posture", source: origin, findings: kept, scope },
83
110
  },
84
111
  );
112
+ keepElsewhere();
85
113
  }
86
114
 
87
115
  function relevanceOf(
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
2
2
  import {
3
3
  investigationEvidenceSubjectRef,
4
4
  metricsScope,
5
+ metricsSelectedPod,
5
6
  projectInvestigationEvidence,
6
7
  type InvestigationEvidenceTarget,
7
8
  } from "../index";
@@ -1640,3 +1641,42 @@ describe("query_prometheus evidence", () => {
1640
1641
  expect(groups[0].observations[1].changedFromPrevious).toBe(true);
1641
1642
  });
1642
1643
  });
1644
+
1645
+ describe("metricsSelectedPod", () => {
1646
+ const selector = (...matchers: [string, string, string][]) => ({
1647
+ metric: "kube_pod_container_status_restarts_total",
1648
+ matchers: matchers.map(([label, op, value]) => ({ label, op, value })),
1649
+ });
1650
+ it("names the one Pod every selector selects exactly", () => {
1651
+ expect(
1652
+ metricsSelectedPod([
1653
+ selector(["namespace", "=", "shop"], ["pod", "=~", "^(api-0)$"]),
1654
+ selector(["namespace", "=", "shop"], ["pod", "=", "api-0"]),
1655
+ ]),
1656
+ ).toBe("api-0");
1657
+ });
1658
+ it("names no Pod for a set, a pattern, disagreeing selectors or a selector without one", () => {
1659
+ expect(
1660
+ metricsSelectedPod([selector(["pod", "=~", "^(api-0|api-1)$"])]),
1661
+ ).toBeUndefined();
1662
+ expect(
1663
+ metricsSelectedPod([selector(["pod", "=~", "api-.*"])]),
1664
+ ).toBeUndefined();
1665
+ expect(
1666
+ metricsSelectedPod([selector(["pod", "!=", "api-0"])]),
1667
+ ).toBeUndefined();
1668
+ expect(
1669
+ metricsSelectedPod([
1670
+ selector(["pod", "=", "api-0"]),
1671
+ selector(["pod", "=", "api-1"]),
1672
+ ]),
1673
+ ).toBeUndefined();
1674
+ expect(
1675
+ metricsSelectedPod([
1676
+ selector(["pod", "=", "api-0"]),
1677
+ selector(["namespace", "=", "shop"]),
1678
+ ]),
1679
+ ).toBeUndefined();
1680
+ expect(metricsSelectedPod([])).toBeUndefined();
1681
+ });
1682
+ });
@@ -338,8 +338,10 @@ export function adaptPrometheusRules(
338
338
  // every alerting rule (a name or group filter never looked at the rest), a
339
339
  // complete list, every rule evaluated, and every returned instance placed
340
340
  // in another namespace outright. An instance this projection merely fails
341
- // to recognize is not evidence of absence.
341
+ // to recognize is not evidence of absence. A run with no resource has
342
+ // nothing for an alert to miss.
342
343
  if (
344
+ builder.target.name &&
343
345
  source.confirmedSuccess &&
344
346
  !truncated &&
345
347
  !namesTarget &&
@@ -440,6 +442,30 @@ function exactPodSet(value: string): string[] | undefined {
440
442
  ? names
441
443
  : undefined;
442
444
  }
445
+ /**
446
+ * The one Pod a query is about, when every selector names exactly that Pod
447
+ * and nothing else. A query over two Pods is about neither alone, and a
448
+ * selector without a pod matcher is about whatever else it selects.
449
+ */
450
+ export function metricsSelectedPod(
451
+ selectors: readonly InvestigationMetricsSelector[],
452
+ ): string | undefined {
453
+ let pod: string | undefined;
454
+ for (const selector of selectors) {
455
+ const named = selector.matchers.filter(
456
+ (matcher) => matcher.label === "pod",
457
+ );
458
+ if (named.length === 0) return undefined;
459
+ for (const { op, value } of named) {
460
+ const names =
461
+ op === "=" ? [value] : op === "=~" ? exactPodSet(value) : undefined;
462
+ if (names?.length !== 1 || (pod !== undefined && names[0] !== pod))
463
+ return undefined;
464
+ pod = names[0];
465
+ }
466
+ }
467
+ return pod;
468
+ }
443
469
  /**
444
470
  * Whether a workload identity label names the target: the label
445
471
  * kube-state-metrics uses for the kind (`deployment`, `job_name`, …) or a
@@ -0,0 +1,111 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { renderToStaticMarkup } from "react-dom/server";
3
+
4
+ import { MetricsBody, metricsReading } from "./metrics";
5
+ import type { EvidenceDataOf } from "../cardParts";
6
+
7
+ const QUERY =
8
+ 'sum(kube_pod_container_status_restarts_total{namespace="gl-crash-config",pod=~"^(api-7c6f9c7bb9-p9czp)$",container="api"})';
9
+
10
+ function range(query: string): EvidenceDataOf<"metrics"> {
11
+ return {
12
+ type: "metrics",
13
+ origin: "query",
14
+ query,
15
+ mode: "range",
16
+ series: [
17
+ {
18
+ labels: {},
19
+ dataPoints: [
20
+ { timestamp: 1_788_679_043, value: 1 },
21
+ { timestamp: 1_788_682_643, value: 2 },
22
+ ],
23
+ },
24
+ ],
25
+ truncated: false,
26
+ } as EvidenceDataOf<"metrics">;
27
+ }
28
+
29
+ const occurrences = (html: string, text: string) => html.split(text).length - 1;
30
+
31
+ describe("MetricsBody", () => {
32
+ it("prints a long query once, in full, instead of also cutting it short above the chart", () => {
33
+ const html = renderToStaticMarkup(<MetricsBody data={range(QUERY)} />);
34
+ expect(occurrences(html, "kube_pod_container_status_restarts_total")).toBe(
35
+ 1,
36
+ );
37
+ expect(html).not.toContain("investigation-metrics-axis-label");
38
+ });
39
+
40
+ it("keeps a short query on the line above the chart", () => {
41
+ const html = renderToStaticMarkup(<MetricsBody data={range("sum(up)")} />);
42
+ expect(html).toContain("investigation-metrics-axis-label");
43
+ expect(occurrences(html, "sum(up)")).toBe(1);
44
+ });
45
+
46
+ it("keeps a long label that is not the query, cut short", () => {
47
+ const label = `Restarts of every container in the checkout service ${"x".repeat(40)}`;
48
+ const html = renderToStaticMarkup(
49
+ <MetricsBody data={{ ...range(QUERY), label }} />,
50
+ );
51
+ expect(html).toContain("investigation-metrics-axis-label");
52
+ expect(html).toContain("Restarts of every container");
53
+ });
54
+
55
+ it("draws a short chart only when asked", () => {
56
+ expect(
57
+ renderToStaticMarkup(<MetricsBody data={range(QUERY)} size="short" />),
58
+ ).toContain("height:140px");
59
+ expect(
60
+ renderToStaticMarkup(<MetricsBody data={range(QUERY)} />),
61
+ ).not.toContain("height:140px");
62
+ });
63
+ });
64
+
65
+ describe("metricsReading", () => {
66
+ const points = (...values: (number | null)[]) =>
67
+ values.map((value, index) => ({ timestamp: 1_788_679_043 + index, value }));
68
+ const data = (
69
+ series: ReturnType<typeof points>[],
70
+ mode: "range" | "instant" = "range",
71
+ ) =>
72
+ ({
73
+ ...range("up"),
74
+ // Values read in the chart's own unit formatting.
75
+ unit: "count",
76
+ mode,
77
+ series: series.map((dataPoints) => ({ labels: {}, dataPoints })),
78
+ }) as EvidenceDataOf<"metrics">;
79
+
80
+ it("reads one series from its first to its last value", () => {
81
+ expect(metricsReading(data([points(3, 9, 12)]))).toBe("3 → 12");
82
+ });
83
+
84
+ it("adds a peak or a low that the first and last values hide", () => {
85
+ expect(metricsReading(data([points(3, 40, 12)]))).toBe("3 → 12 · peak 40");
86
+ // A dip to zero or a counter reset is the incident; it must not fold away.
87
+ expect(metricsReading(data([points(1, 0, 1)]))).toBe("1 → 1 · low 0");
88
+ expect(metricsReading(data([points(100, 0, 101)]))).toBe(
89
+ "100 → 101 · low 0",
90
+ );
91
+ });
92
+
93
+ it("says when samples are missing and reads several series by their range", () => {
94
+ expect(metricsReading(data([points(5, 7, null, null)]))).toBe(
95
+ "5 → 7 · with gaps",
96
+ );
97
+ expect(metricsReading(data([points(1, 2), points(8, 3)]))).toBe(
98
+ "2 series · 1 to 8",
99
+ );
100
+ // A series with no samples still counts as one of the series read.
101
+ expect(metricsReading(data([points(1, 2), points(null)]))).toBe(
102
+ "2 series · 1 to 2 · with gaps",
103
+ );
104
+ });
105
+
106
+ it("reads an instant value as itself and says nothing without a sample", () => {
107
+ expect(metricsReading(data([points(4)], "instant"))).toBe("4");
108
+ expect(metricsReading(data([points(null)]))).toBeUndefined();
109
+ expect(metricsReading(data([]))).toBeUndefined();
110
+ });
111
+ });
@@ -70,20 +70,62 @@ function MetricsValueTable({
70
70
  );
71
71
  }
72
72
 
73
+ /**
74
+ * One line of what a folded chart shows, so its card says something before it
75
+ * is opened: one series' first and last value with any low or peak between
76
+ * them (a dip, a counter reset), or the range across several series. Missing
77
+ * samples are said, not smoothed over. Undefined when nothing was captured.
78
+ */
79
+ export function metricsReading(
80
+ data: EvidenceDataOf<"metrics">,
81
+ ): string | undefined {
82
+ const unit = data.unit ?? "";
83
+ const format = (value: number) => formatMetricValue(value, unit);
84
+ const values = data.series.map((series) =>
85
+ finiteSamples(series).map((point) => point.value as number),
86
+ );
87
+ const all = values.flat();
88
+ if (all.length === 0) return undefined;
89
+ const low = Math.min(...all);
90
+ const peak = Math.max(...all);
91
+ const gaps = data.series.some((series) =>
92
+ series.dataPoints.some((point) => typeof point.value !== "number"),
93
+ )
94
+ ? " · with gaps"
95
+ : "";
96
+ if (data.series.length > 1) {
97
+ return `${data.series.length} series · ${format(low)} to ${format(peak)}${gaps}`;
98
+ }
99
+ const samples = values[0];
100
+ const first = samples[0];
101
+ const last = samples[samples.length - 1];
102
+ if (data.mode === "instant" || samples.length === 1) {
103
+ return `${format(last)}${gaps}`;
104
+ }
105
+ const between = [
106
+ low < first && low < last ? `low ${format(low)}` : "",
107
+ peak > first && peak > last ? `peak ${format(peak)}` : "",
108
+ ].filter(Boolean);
109
+ return [`${format(first)} → ${format(last)}`, ...between].join(" · ") + gaps;
110
+ }
111
+
112
+ /** Rendered height of a chart drawn short beside the story's prose. */
113
+ const SHORT_CHART_HEIGHT_PX = 140;
114
+
73
115
  export function MetricsBody({
74
116
  data,
75
117
  changeCoverage,
118
+ size = "full",
76
119
  }: {
77
120
  data: EvidenceDataOf<"metrics">;
78
121
  changeCoverage?: MetricsChangeCoverage;
122
+ /** "short" draws a low chart, for a placed card the story does not rest on. */
123
+ size?: "full" | "short";
79
124
  }) {
80
125
  const annotations = changeCoverage?.markers;
81
126
  const unit = data.unit ?? "";
82
127
  const axisLabel = data.label ?? data.query;
83
128
  const axisTruncated = axisLabel.length > METRICS_AXIS_LABEL_MAX_CHARS;
84
- const axisText = axisTruncated
85
- ? `${axisLabel.slice(0, METRICS_AXIS_LABEL_MAX_CHARS - 1)}…`
86
- : axisLabel;
87
129
  const domain = metricsDomain(data);
88
130
  const windowText = domain
89
131
  ? `${new Date(domain.start * 1000).toLocaleString()} to ${new Date(domain.end * 1000).toLocaleString()}`
@@ -139,19 +181,26 @@ export function MetricsBody({
139
181
  return (
140
182
  <div className="space-y-2">
141
183
  <div className="flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5 text-xs">
142
- <Tooltip
143
- content={axisLabel}
144
- delay={200}
145
- position="top"
146
- disabled={!axisTruncated}
147
- >
148
- <span
149
- className="min-w-0 truncate font-mono text-theme-text-secondary"
150
- data-testid="investigation-metrics-axis-label"
184
+ {/* A query too long for this line is printed in full below the
185
+ chart; repeating its first half here would say it twice. A
186
+ distinct label keeps its line, cut short with the rest on hover. */}
187
+ {axisTruncated && axisLabel === data.query ? null : (
188
+ <Tooltip
189
+ content={axisLabel}
190
+ delay={200}
191
+ position="top"
192
+ disabled={!axisTruncated}
151
193
  >
152
- {axisText}
153
- </span>
154
- </Tooltip>
194
+ <span
195
+ className="min-w-0 truncate font-mono text-theme-text-secondary"
196
+ data-testid="investigation-metrics-axis-label"
197
+ >
198
+ {axisTruncated
199
+ ? `${axisLabel.slice(0, METRICS_AXIS_LABEL_MAX_CHARS - 1)}…`
200
+ : axisLabel}
201
+ </span>
202
+ </Tooltip>
203
+ )}
155
204
  {unit ? (
156
205
  <span className="text-theme-text-tertiary">({unit})</span>
157
206
  ) : null}
@@ -169,7 +218,9 @@ export function MetricsBody({
169
218
  unit={unit}
170
219
  annotations={annotations}
171
220
  domain={domain}
172
- layout="auto"
221
+ {...(size === "short"
222
+ ? { layout: "dashboard" as const, height: SHORT_CHART_HEIGHT_PX }
223
+ : { layout: "auto" as const })}
173
224
  />
174
225
  {charted.length > 1 ? (
175
226
  <SeriesLegend
@@ -30,16 +30,29 @@ describe("storyExcerpt", () => {
30
30
  });
31
31
  });
32
32
 
33
- it("shows a chart only when the card is the cause or the symptom, and never compact", () => {
33
+ it("shows a placed chart whatever its role, folding a compact one the story does not rest on", () => {
34
34
  const metrics = observation({ type: "metrics", origin: "query" } as never);
35
35
  expect(
36
36
  storyExcerpt(metrics, [{ role: "context" }], { compact: false }),
37
- ).toBeUndefined();
37
+ ).toEqual({ kind: "chart", size: "short", folded: false });
38
+ expect(
39
+ storyExcerpt(metrics, [{ role: "rules_out" }], { compact: true }),
40
+ ).toEqual({ kind: "chart", size: "short", folded: true });
41
+ // The agent marks a card compact for the prose's flow, so a symptom
42
+ // placed compact still starts open.
38
43
  expect(
39
- storyExcerpt(metrics, [{ role: "symptom" }], { compact: false }),
40
- ).toEqual({ kind: "chart" });
44
+ storyExcerpt(metrics, [{ role: "symptom" }], { compact: true }),
45
+ ).toEqual({ kind: "chart", size: "full", folded: false });
41
46
  expect(
42
- storyExcerpt(metrics, [{ role: "cause" }], { compact: true }),
47
+ storyExcerpt(metrics, [{ role: "context" }, { role: "cause" }], {
48
+ compact: true,
49
+ }),
50
+ ).toEqual({ kind: "chart", size: "full", folded: false });
51
+ expect(
52
+ storyExcerpt(metrics, [{ role: "cause" }], {
53
+ compact: true,
54
+ preview: true,
55
+ }),
43
56
  ).toBeUndefined();
44
57
  });
45
58
 
@@ -19,15 +19,18 @@ export const VISIBLE_LOG_EVIDENCE_LINES = 12;
19
19
  * What a card placed in the story shows inline, under its header, before the
20
20
  * fold. The citation decides it: the lines Radar selected, the row a subject
21
21
  * names, the workload's own row in a ranking, the findings on it, or the
22
- * chart when the card is the cause or the symptom. Nothing here is the
23
- * agent's text; every excerpt is a slice of Radar's record.
22
+ * chart. The role the agent gave the card never hides any of it; it only
23
+ * sizes a chart, full height for what the story rests on and short for the
24
+ * rest. A compact marker starts a chart folded behind the card's chevron,
25
+ * except one the story rests on. Nothing here is the agent's text; every
26
+ * excerpt is a slice of Radar's record.
24
27
  */
25
28
  export type StoryExcerpt =
26
29
  | { kind: "lines"; head: string[]; rest: string[] }
27
30
  | { kind: "rows"; entries: ReturnType<typeof namedInventoryRows> }
28
31
  | { kind: "ranking"; rows: InvestigationRankingRow[] }
29
32
  | { kind: "posture"; findings: InvestigationPostureFinding[] }
30
- | { kind: "chart" };
33
+ | { kind: "chart"; size: "full" | "short"; folded: boolean };
31
34
 
32
35
  export interface StoryExcerptItem {
33
36
  role?: DiagnosisEvidenceRole;
@@ -37,7 +40,7 @@ export interface StoryExcerptItem {
37
40
  export function storyExcerpt(
38
41
  observation: InvestigationEvidenceObservation,
39
42
  items: readonly StoryExcerptItem[],
40
- options: { compact: boolean; scopeNamespace?: string },
43
+ options: { compact: boolean; preview?: boolean; scopeNamespace?: string },
41
44
  ): StoryExcerpt | undefined {
42
45
  const data = observation.data;
43
46
  // The lines are the card: a compact log card keeps them.
@@ -48,6 +51,21 @@ export function storyExcerpt(
48
51
  if (lines.length === 0) return undefined;
49
52
  return { kind: "lines", head: lines.slice(-2), rest: lines.slice(0, -2) };
50
53
  }
54
+ // So is the chart: a compact card drops the agent's note, not Radar's
55
+ // record. Compact folds the chart, but the agent marks cards compact for
56
+ // the prose's flow, not their weight, so a cause or symptom stays open.
57
+ // Only the collapsed preview, which bounds its height, leaves it out.
58
+ if (data.type === "metrics") {
59
+ if (options.preview) return undefined;
60
+ const rests = items.some(
61
+ (item) => item.role === "cause" || item.role === "symptom",
62
+ );
63
+ return {
64
+ kind: "chart",
65
+ size: rests ? "full" : "short",
66
+ folded: options.compact && !rests,
67
+ };
68
+ }
51
69
  if (options.compact) return undefined;
52
70
  const named = (row: { kind: string; namespace?: string; name: string }) =>
53
71
  items.some(
@@ -59,13 +77,6 @@ export function storyExcerpt(
59
77
  item.subject.namespace === row.namespace),
60
78
  );
61
79
  switch (data.type) {
62
- case "metrics":
63
- // A chart placed as the cause or the symptom is the card.
64
- return items.some(
65
- (item) => item.role === "cause" || item.role === "symptom",
66
- )
67
- ? { kind: "chart" }
68
- : undefined;
69
80
  case "inventory": {
70
81
  const entries = namedInventoryRows(
71
82
  data.resources as InvestigationResourceSummary[],
@@ -3,7 +3,7 @@
3
3
  // absent here is internal: exported from its own file only so a sibling can
4
4
  // reach it, and free to move between files without affecting a caller.
5
5
 
6
- export { metricsScope } from "./adapters/prometheus";
6
+ export { metricsScope, metricsSelectedPod } from "./adapters/prometheus";
7
7
  export { projectInvestigationEvidence } from "./builder";
8
8
  export {
9
9
  investigationActivitySourceDomId,
@@ -23,4 +23,6 @@ export const EvidenceNavigationContext = createContext<{
23
23
  caseByGroup?: ReadonlyMap<string, InvestigationCaseItem[]>;
24
24
  /** The hypothesis each `rules_out` item excludes, keyed by item. */
25
25
  excludedByItem?: ReadonlyMap<string, string>;
26
+ /** The story card a reference just navigated to, so a folded chart opens. */
27
+ storyReveal?: { domId: string; requestId: number };
26
28
  }>({});
@@ -560,6 +560,8 @@ export interface InvestigationMetricsEvidence {
560
560
  selectorsUnknown?: boolean;
561
561
  subject?: DiagnosisResourceRef;
562
562
  pods?: number;
563
+ /** The pods a diagnose chart summed, by name, when its bundle listed them all. */
564
+ podNames?: string[];
563
565
  partial?: boolean;
564
566
  }
565
567
  export interface InvestigationEvidenceObservation {
@@ -96,6 +96,11 @@ export function partitionInvestigationEvidence(
96
96
  * target is folded into a second tier. Broader results stay cited-only.
97
97
  */
98
98
  inventory = false,
99
+ /**
100
+ * The run stopped without an assessment, so nothing will ever be cited:
101
+ * broader results are all it has to show, and are not withheld.
102
+ */
103
+ showUncited = false,
99
104
  ) {
100
105
  // Selection: legacy root-cause links plus every placed agent item, of any
101
106
  // role (placement promotes a group into main the way a citation does; the
@@ -126,7 +131,7 @@ export function partitionInvestigationEvidence(
126
131
  // reader knows the agent ran queries it did not build its case on.
127
132
  let hiddenMetrics = 0;
128
133
  for (const group of groups) {
129
- const broader = group.latest.relevance === "broader";
134
+ const broader = group.latest.relevance === "broader" && !showUncited;
130
135
  // Citations select tool results, not individual rows in a broad search.
131
136
  // Only a focused, unambiguous fact can be promoted by a source citation.
132
137
  // An agent item names this observation when its subject does, or when the