@skyhook-io/radar-app 1.18.1 → 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 (136) hide show
  1. package/package.json +4 -4
  2. package/src/App.tsx +23 -9
  3. package/src/api/client.deleteResource.test.tsx +111 -0
  4. package/src/api/client.resourceAudit.test.tsx +57 -0
  5. package/src/api/client.resourcePath.test.ts +107 -0
  6. package/src/api/client.ts +136 -37
  7. package/src/api/diagnose.test.ts +33 -2
  8. package/src/api/diagnose.ts +93 -3
  9. package/src/api/radarFeatures.ts +1 -0
  10. package/src/components/capacity/CapacityDemand.tsx +6 -3
  11. package/src/components/capacity/CapacityOverview.tsx +14 -7
  12. package/src/components/capacity/CapacityPoolDetail.tsx +7 -5
  13. package/src/components/capacity/ClusterSchedulingCard.tsx +3 -3
  14. package/src/components/capacity/shared.tsx +9 -5
  15. package/src/components/cnpg/CNPGOverview.tsx +4 -1
  16. package/src/components/cnpg/actions/useCNPGWriteGuard.tsx +1 -0
  17. package/src/components/diagnose/AIMarkdown.tsx +1 -1
  18. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  19. package/src/components/diagnose/AgentControls.tsx +53 -6
  20. package/src/components/diagnose/AgentSetupNotice.tsx +1 -1
  21. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  22. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  23. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  24. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  25. package/src/components/diagnose/ApplyDialog.test.tsx +10 -0
  26. package/src/components/diagnose/ApplyDialog.tsx +8 -1
  27. package/src/components/diagnose/AssessmentCard.tsx +99 -8
  28. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  29. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  30. package/src/components/diagnose/DiagnoseContext.tsx +205 -9
  31. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  32. package/src/components/diagnose/DiagnoseSurface.tsx +98 -21
  33. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  34. package/src/components/diagnose/Home.test.tsx +182 -5
  35. package/src/components/diagnose/Home.tsx +168 -36
  36. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  37. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  38. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  39. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +119 -2
  40. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  41. package/src/components/diagnose/InvestigationEvidenceSections.tsx +11 -6
  42. package/src/components/diagnose/InvestigationView.tsx +203 -42
  43. package/src/components/diagnose/LocalDiagnoseAction.tsx +23 -16
  44. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  45. package/src/components/diagnose/QuestionComposer.tsx +487 -0
  46. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  47. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  48. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  49. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  50. package/src/components/diagnose/assessmentCopy.ts +16 -0
  51. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  52. package/src/components/diagnose/investigationCase.ts +33 -1
  53. package/src/components/diagnose/investigationEvidence/adapters/changes.ts +36 -1
  54. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  55. package/src/components/diagnose/investigationEvidence/adapters/crossplane.test.tsx +85 -0
  56. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +8 -0
  57. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +1 -0
  58. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  59. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +42 -1
  60. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +29 -2
  61. package/src/components/diagnose/investigationEvidence/adapters/testdata/crossplane-paused-get-resource.json +28 -0
  62. package/src/components/diagnose/investigationEvidence/bodies/index.tsx +2 -0
  63. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  64. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  65. package/src/components/diagnose/investigationEvidence/bodies/workload.tsx +5 -1
  66. package/src/components/diagnose/investigationEvidence/builder.ts +3 -1
  67. package/src/components/diagnose/investigationEvidence/cardParts.tsx +7 -2
  68. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  69. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  70. package/src/components/diagnose/investigationEvidence/identity.test.ts +1 -1
  71. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  72. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  73. package/src/components/diagnose/investigationEvidence/observations.ts +7 -3
  74. package/src/components/diagnose/investigationEvidence/projection.test.ts +57 -3
  75. package/src/components/diagnose/investigationEvidence/types.ts +2 -0
  76. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  77. package/src/components/diagnose/investigationEvidencePresentation.test.ts +36 -2
  78. package/src/components/diagnose/investigationEvidencePresentation.ts +33 -8
  79. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  80. package/src/components/diagnose/investigationFocus.ts +132 -0
  81. package/src/components/diagnose/parts.test.tsx +20 -0
  82. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  83. package/src/components/diagnose/questionSuggestions.ts +150 -0
  84. package/src/components/diagnose/storyParts.test.tsx +66 -0
  85. package/src/components/diagnose/target.test.ts +143 -2
  86. package/src/components/diagnose/target.ts +109 -7
  87. package/src/components/diagnose/testdata/story-runs.json +474 -0
  88. package/src/components/diagnose/verdictText.test.tsx +87 -0
  89. package/src/components/diagnose/verdictText.ts +68 -0
  90. package/src/components/helm/ChartBrowser.tsx +4 -4
  91. package/src/components/helm/HelmReleaseDrawer.tsx +6 -2
  92. package/src/components/helm/HelmView.tsx +34 -23
  93. package/src/components/helm/InstallWizard.tsx +6 -2
  94. package/src/components/helm/ValuesViewer.test.tsx +1 -0
  95. package/src/components/helm/ValuesViewer.tsx +4 -2
  96. package/src/components/home/ClusterHealthCard.tsx +40 -59
  97. package/src/components/home/HomeAgentBlock.test.tsx +113 -0
  98. package/src/components/home/HomeAgentBlock.tsx +94 -0
  99. package/src/components/home/HomeView.tsx +5 -6
  100. package/src/components/home/MCPSetupDialog.test.tsx +27 -2
  101. package/src/components/home/MCPSetupDialog.tsx +14 -2
  102. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  103. package/src/components/home/RadarVersionLine.tsx +3 -28
  104. package/src/components/home/mcpToolCatalog.ts +29 -2
  105. package/src/components/issues/IssuesPane.render.test.tsx +5 -5
  106. package/src/components/nav/PrimaryNavRail.tsx +34 -2
  107. package/src/components/product-hunt/ProductHuntNotice.render.test.tsx +120 -0
  108. package/src/components/product-hunt/ProductHuntNotice.test.ts +121 -0
  109. package/src/components/product-hunt/ProductHuntNotice.tsx +202 -0
  110. package/src/components/product-hunt/launchWindow.ts +78 -0
  111. package/src/components/product-hunt/useProductHuntRailEntry.test.tsx +76 -0
  112. package/src/components/product-hunt/useProductHuntRailEntry.ts +27 -0
  113. package/src/components/resources/CompositeRenderer.tsx +4 -0
  114. package/src/components/resources/ResourcesView.tsx +1 -1
  115. package/src/components/settings/LocalConnectionSettings.tsx +1 -0
  116. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  117. package/src/components/ui/Omnibar.tsx +47 -3
  118. package/src/components/ui/RadarOmnibar.test.tsx +19 -0
  119. package/src/components/ui/RadarOmnibar.tsx +12 -0
  120. package/src/components/ui/SearchSyntaxHelp.test.tsx +39 -0
  121. package/src/components/ui/SearchSyntaxHelp.tsx +23 -2
  122. package/src/components/ui/UpdateNotification.test.tsx +2 -0
  123. package/src/components/ui/UpdateNotification.tsx +32 -5
  124. package/src/components/usage-data/UsageDataPrompt.tsx +19 -1
  125. package/src/components/whats-new/WhatsNewDialog.test.tsx +3 -3
  126. package/src/components/whats-new/releaseNotes.ts +60 -1
  127. package/src/components/workload/WorkloadView.tsx +10 -4
  128. package/src/components/workspace/layout.tsx +2 -1
  129. package/src/contexts/CapabilitiesContext.tsx +1 -0
  130. package/src/hooks/useAgentSignin.test.tsx +190 -0
  131. package/src/hooks/useAgentSignin.ts +160 -0
  132. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
  133. package/src/hooks/useGitOpsWriteGuard.test.tsx +126 -2
  134. package/src/hooks/useGitOpsWriteGuard.ts +25 -3
  135. package/src/hooks/useResolvedGitOpsOwner.ts +14 -9
  136. package/src/index.css +85 -0
@@ -144,6 +144,41 @@ describe("ResultCard under the story contract", () => {
144
144
  expect(html).toContain("Previous logs: could not be read");
145
145
  });
146
146
 
147
+ it("folds Radar's routine limits into one muted line beneath Still open", () => {
148
+ const routine = [
149
+ "Cluster-scoped admission changes: Radar has recorded changes only since 2026-10-27T23:42:31Z; earlier changes in the window are unknown.",
150
+ "Container logs: Only part of the logs was checked.",
151
+ ];
152
+ const html = renderToStaticMarkup(
153
+ <ResultCard
154
+ diagnosis={storyDiagnosis}
155
+ section="conclusion"
156
+ assessmentRoutineLimits={routine}
157
+ />,
158
+ );
159
+ const stillOpen = html.slice(
160
+ html.indexOf("data-assessment-unresolved"),
161
+ html.indexOf("data-assessment-routine-limits"),
162
+ );
163
+ expect(stillOpen).toContain("Whether the Atlas password was rotated");
164
+ expect(stillOpen).not.toContain("Radar has recorded changes only since");
165
+ expect(html).toContain("Radar&#x27;s coverage · 2 routine limits");
166
+ expect(html).toContain('aria-expanded="false"');
167
+ // Folded, never dropped: the lines stay in the document for the disclosure.
168
+ expect(html).toContain("Radar has recorded changes only since");
169
+
170
+ // Without open questions the folded line still renders on its own.
171
+ const alone = renderToStaticMarkup(
172
+ <ResultCard
173
+ diagnosis={{ ...storyDiagnosis, unresolved: [] }}
174
+ section="conclusion"
175
+ assessmentRoutineLimits={routine.slice(1)}
176
+ />,
177
+ );
178
+ expect(alone).not.toContain("data-assessment-unresolved");
179
+ expect(alone).toContain("Radar&#x27;s coverage · 1 routine limit<");
180
+ });
181
+
147
182
  it("says nothing when the agent listed nothing unresolved: the certainty word carries it", () => {
148
183
  const html = renderToStaticMarkup(
149
184
  <ResultCard
@@ -283,6 +318,24 @@ describe("assessmentCopyText", () => {
283
318
  text.indexOf("Still open:"),
284
319
  );
285
320
  });
321
+ it("copies routine limits after the steps, apart from Still open", () => {
322
+ const text = assessmentCopyText(storyDiagnosis, {
323
+ limits: ["Previous logs: could not be read"],
324
+ routineLimits: ["Recent changes: Change history is incomplete."],
325
+ });
326
+ expect(text).toContain(
327
+ "Radar's coverage (routine limits):\n- Recent changes: Change history is incomplete.",
328
+ );
329
+ const stillOpen = text.slice(
330
+ text.indexOf("Still open:"),
331
+ text.indexOf("\n\n", text.indexOf("Still open:")),
332
+ );
333
+ expect(stillOpen).toContain("- Previous logs: could not be read");
334
+ expect(stillOpen).not.toContain("Change history is incomplete");
335
+ expect(text.indexOf("Next steps:")).toBeLessThan(
336
+ text.indexOf("Radar's coverage"),
337
+ );
338
+ });
286
339
  it("names the recommended step and counts the rest for a legacy remediation list", () => {
287
340
  const text = assessmentCopyText(
288
341
  {
@@ -297,6 +350,19 @@ describe("assessmentCopyText", () => {
297
350
  expect(text).toContain("2 more steps in Radar.");
298
351
  });
299
352
 
353
+ it("says what was asked about the resource, right under where", () => {
354
+ const text = assessmentCopyText(storyDiagnosis, {
355
+ context: {
356
+ target: "Deployment shop/api",
357
+ asked: "users saw errors\n yesterday",
358
+ },
359
+ });
360
+ expect(text.split("\n\n").slice(0, 2)).toEqual([
361
+ "**Deployment shop/api**",
362
+ "Asked: “users saw errors yesterday”",
363
+ ]);
364
+ });
365
+
300
366
  it("puts the healthy word on the headline and the flags before Still open", () => {
301
367
  const text = assessmentCopyText(
302
368
  {
@@ -1,6 +1,15 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
 
3
- import { formatInvestigationTarget, runTargetKey } from "./target";
3
+ import {
4
+ canonicalKind,
5
+ formatInvestigationTarget,
6
+ formatInvestigationTitle,
7
+ formatQuestionScope,
8
+ isQuestionOnly,
9
+ questionAskedAt,
10
+ rerunOpening,
11
+ runTargetKey,
12
+ } from "./target";
4
13
 
5
14
  describe("investigation target identity", () => {
6
15
  it("uses one running key for singular Kinds and plural resource names", () => {
@@ -34,7 +43,7 @@ describe("investigation target identity", () => {
34
43
  namespace: "prod",
35
44
  name: "api",
36
45
  }),
37
- ).toBe("Deployment.apps prod/api");
46
+ ).toBe("Deployment prod/api");
38
47
  expect(
39
48
  formatInvestigationTarget({
40
49
  kind: "pods",
@@ -56,3 +65,135 @@ describe("investigation target identity", () => {
56
65
  ).toBe("Service prod/api");
57
66
  });
58
67
  });
68
+
69
+ describe("question runs", () => {
70
+ const questionOnly = {
71
+ kind: "",
72
+ group: "",
73
+ namespace: "",
74
+ name: "",
75
+ question: "checkout is slow\n since lunch",
76
+ namespaces: ["shop", "payments"],
77
+ lookBack: "1h",
78
+ };
79
+
80
+ it("names a question-only run by its question on one line", () => {
81
+ expect(isQuestionOnly(questionOnly)).toBe(true);
82
+ expect(formatInvestigationTitle(questionOnly)).toBe(
83
+ "checkout is slow since lunch",
84
+ );
85
+ expect(formatQuestionScope(questionOnly)).toBe("shop, payments · last 1h");
86
+ const askedAt = "2026-10-27T09:00:00Z";
87
+ expect(
88
+ formatQuestionScope(
89
+ { ...questionOnly, askedAt },
90
+ new Date("2026-10-28T12:00:00Z"),
91
+ ),
92
+ ).toBe(
93
+ `shop, payments · 1h before ${new Date(askedAt).toLocaleString(undefined, { month: "short", day: "numeric", hour: "numeric", minute: "2-digit" })}`,
94
+ );
95
+ expect(formatQuestionScope({ ...questionOnly, namespaces: [] })).toBe(
96
+ "All namespaces · last 1h",
97
+ );
98
+ });
99
+
100
+ it("names a question about a resource by the resource", () => {
101
+ const pinned = {
102
+ ...questionOnly,
103
+ kind: "Deployment",
104
+ group: "apps",
105
+ namespace: "shop",
106
+ name: "checkout",
107
+ };
108
+ expect(isQuestionOnly(pinned)).toBe(false);
109
+ expect(formatInvestigationTitle(pinned)).toBe("Deployment shop/checkout");
110
+ });
111
+ });
112
+
113
+ describe("rerunOpening", () => {
114
+ const now = Date.parse("2026-10-28T12:00:00Z");
115
+ it("starts the same question again in a new session", () => {
116
+ expect(
117
+ rerunOpening(
118
+ {
119
+ kind: "",
120
+ group: "",
121
+ namespace: "",
122
+ name: "",
123
+ question: "checkout is slow",
124
+ namespaces: ["shop"],
125
+ lookBack: "6h",
126
+ createdAt: "2026-10-27T09:00:00Z",
127
+ },
128
+ now,
129
+ ),
130
+ ).toEqual({
131
+ kind: "",
132
+ group: "",
133
+ namespace: "",
134
+ name: "",
135
+ issueId: undefined,
136
+ fresh: true,
137
+ question: "checkout is slow",
138
+ namespaces: ["shop"],
139
+ lookBack: "6h",
140
+ askedAt: "2026-10-27T09:00:00Z",
141
+ });
142
+ });
143
+
144
+ it("keeps the first asking time through a chain of re-runs, and none without a question", () => {
145
+ const base = {
146
+ kind: "Deployment",
147
+ group: "apps",
148
+ namespace: "shop",
149
+ name: "api",
150
+ createdAt: "2026-10-28T09:00:00Z",
151
+ };
152
+ expect(
153
+ rerunOpening(
154
+ {
155
+ ...base,
156
+ question: "why?",
157
+ askedAt: "2026-10-27T09:00:00Z",
158
+ },
159
+ now,
160
+ ).askedAt,
161
+ ).toBe("2026-10-27T09:00:00Z");
162
+ expect(rerunOpening(base, now).askedAt).toBeUndefined();
163
+ });
164
+ });
165
+
166
+ describe("questionAskedAt", () => {
167
+ const now = Date.parse("2026-10-28T12:00:00Z");
168
+ it("keeps a recent asking time and drops one past Radar's window", () => {
169
+ const run = {
170
+ kind: "",
171
+ group: "",
172
+ namespace: "",
173
+ name: "",
174
+ question: "why?",
175
+ createdAt: "2026-10-20T12:00:00Z",
176
+ };
177
+ expect(questionAskedAt(run, now)).toBe("2026-10-20T12:00:00Z");
178
+ expect(
179
+ questionAskedAt({ ...run, createdAt: "2026-09-01T12:00:00Z" }, now),
180
+ ).toBeUndefined();
181
+ expect(
182
+ questionAskedAt({ ...run, question: undefined }, now),
183
+ ).toBeUndefined();
184
+ });
185
+ });
186
+
187
+ describe("canonicalKind", () => {
188
+ it("names a resource by its Kind however the caller spelled it", () => {
189
+ expect(canonicalKind("deployments", "")).toBe("Deployment");
190
+ expect(canonicalKind("deployment", "apps")).toBe("Deployment");
191
+ expect(canonicalKind("Deployment", "apps")).toBe("Deployment");
192
+ expect(canonicalKind("pods", "")).toBe("Pod");
193
+ });
194
+
195
+ it("keeps a group's own Kind when its plural matches a core one", () => {
196
+ expect(canonicalKind("PodMetrics", "metrics.k8s.io")).toBe("PodMetrics");
197
+ expect(canonicalKind("nodes", "metrics.k8s.io")).toBe("NodeMetrics");
198
+ });
199
+ });
@@ -1,8 +1,10 @@
1
1
  import { resourceKey } from "@skyhook-io/k8s-ui";
2
+ import { groupQualifiesLaneId } from "@skyhook-io/k8s-ui/utils/navigation";
2
3
 
3
4
  import {
4
5
  kindToPluralWithGroup,
5
6
  knownKindForPluralWithGroup,
7
+ pluralToKind,
6
8
  } from "../../utils/navigation";
7
9
 
8
10
  export interface InvestigationTargetIdentity {
@@ -29,15 +31,115 @@ export function runTargetKey(
29
31
  );
30
32
  }
31
33
 
32
- // Keep the UI aligned with the CLI and the prompts: a non-core target is shown
33
- // as Kind.api.group, which is the Kubernetes-qualified identity users can copy.
34
+ // A custom resource is shown as Kind.api.group, the Kubernetes-qualified
35
+ // identity users can copy, because its Kind can collide with another
36
+ // group's. A built-in group never collides, so its Kind stands alone.
34
37
  export function formatInvestigationTarget(
35
38
  target: InvestigationTargetIdentity,
36
39
  ): string {
37
- const canonicalKind =
38
- knownKindForPluralWithGroup(target.kind, target.group) ?? target.kind;
39
- const kind = target.group
40
- ? `${canonicalKind}.${target.group}`
41
- : canonicalKind;
40
+ const kind = formatInvestigationKind(target.kind, target.group);
42
41
  return `${kind} ${target.namespace ? `${target.namespace}/` : ""}${target.name}`;
43
42
  }
43
+
44
+ export function formatInvestigationKind(kind: string, group: string): string {
45
+ const canonicalKind = knownKindForPluralWithGroup(kind, group) ?? kind;
46
+ return groupQualifiesLaneId(group)
47
+ ? `${canonicalKind}.${group}`
48
+ : canonicalKind;
49
+ }
50
+
51
+ export interface InvestigationOpening extends InvestigationTargetIdentity {
52
+ question?: string;
53
+ namespaces?: string[];
54
+ lookBack?: string;
55
+ askedAt?: string;
56
+ }
57
+
58
+ // When a run's question was first asked: its own start, unless it re-ran or
59
+ // narrowed an earlier question. A run built from it keeps that time, so its
60
+ // look-back still covers the incident the engineer described.
61
+ // Radar accepts an asking time from the last 30 days; an older question is
62
+ // asked again from now rather than refused.
63
+ const ASKED_AT_LIMIT_MS = 29 * 24 * 60 * 60 * 1000;
64
+
65
+ export function questionAskedAt(
66
+ run: InvestigationOpening & { createdAt: string },
67
+ now = Date.now(),
68
+ ): string | undefined {
69
+ if (!run.question) return undefined;
70
+ const askedAt = run.askedAt ?? run.createdAt;
71
+ const age = now - Date.parse(askedAt);
72
+ return age >= 0 && age < ASKED_AT_LIMIT_MS ? askedAt : undefined;
73
+ }
74
+
75
+ // A run opened by a question alone has no resource: no Apply, no
76
+ // per-resource "running" badge, and its question is its title.
77
+ export function isQuestionOnly(run: InvestigationOpening): boolean {
78
+ return !run.name && !!run.question;
79
+ }
80
+
81
+ // The question's own words name a question-only run; a run about a resource
82
+ // is named by the resource even when it started with a question, because the
83
+ // resource is what a reader scanning the history recognises.
84
+ export function formatInvestigationTitle(run: InvestigationOpening): string {
85
+ return isQuestionOnly(run)
86
+ ? (run.question ?? "").replace(/\s+/g, " ").trim()
87
+ : formatInvestigationTarget(run);
88
+ }
89
+
90
+ // Where and since when a question said to start, in the words the composer's
91
+ // chips use: "shop, payments · last 1h".
92
+ // A run carrying an earlier asking time looks back from then, not from now,
93
+ // so it says when: "shop · 1h before Oct 27, 3:04 PM".
94
+ export function formatQuestionScope(
95
+ run: InvestigationOpening,
96
+ now = new Date(),
97
+ ): string {
98
+ const where = run.namespaces?.length
99
+ ? run.namespaces.join(", ")
100
+ : "All namespaces";
101
+ if (!run.lookBack) return where;
102
+ const asked = run.askedAt ? new Date(run.askedAt) : null;
103
+ if (!asked || Number.isNaN(asked.getTime())) {
104
+ return `${where} · last ${run.lookBack}`;
105
+ }
106
+ const sameDay = asked.toDateString() === now.toDateString();
107
+ const when = asked.toLocaleString(undefined, {
108
+ ...(sameDay ? {} : { month: "short", day: "numeric" }),
109
+ hour: "numeric",
110
+ minute: "2-digit",
111
+ });
112
+ return `${where} · ${run.lookBack} before ${when}`;
113
+ }
114
+
115
+ // Investigate again: a new session about the same thing, started the same
116
+ // way. It carries the issue and the question forward and nothing the earlier
117
+ // run found — being handed the previous answer is the one thing someone
118
+ // clicking it doesn't want.
119
+ export function rerunOpening(
120
+ run: InvestigationOpening & { issueId?: string; createdAt: string },
121
+ now = Date.now(),
122
+ ): InvestigationOpening & { issueId?: string; fresh: true } {
123
+ return {
124
+ kind: run.kind,
125
+ group: run.group,
126
+ namespace: run.namespace,
127
+ name: run.name,
128
+ issueId: run.issueId,
129
+ fresh: true,
130
+ question: run.question,
131
+ namespaces: run.namespaces,
132
+ lookBack: run.lookBack,
133
+ askedAt: questionAskedAt(run, now),
134
+ };
135
+ }
136
+
137
+ // Callers name kinds every way Kubernetes accepts: a route's plural
138
+ // (deployments), an agent's lowercase singular (deployment), or the Kind.
139
+ // A resource someone will read about is named by its Kind.
140
+ export function canonicalKind(kind: string, group: string): string {
141
+ // Resolve within the group first: metrics.k8s.io's "pods" are PodMetrics,
142
+ // not Pods.
143
+ const plural = kindToPluralWithGroup(kind, group);
144
+ return knownKindForPluralWithGroup(plural, group) ?? pluralToKind(plural);
145
+ }