@skyhook-io/radar-app 1.18.2 → 1.20.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 (228) hide show
  1. package/README.md +1 -1
  2. package/package.json +7 -7
  3. package/src/App.tsx +31 -6
  4. package/src/api/application-evidence.ts +63 -0
  5. package/src/api/argoSync.test.ts +22 -0
  6. package/src/api/client.audit-gating.test.tsx +48 -0
  7. package/src/api/client.kueuePosition.test.ts +32 -0
  8. package/src/api/client.kueueQueueWorkloads.test.tsx +71 -0
  9. package/src/api/client.resource-identity.test.ts +3 -0
  10. package/src/api/client.resourceIssues.test.tsx +239 -0
  11. package/src/api/client.resourcePath.test.ts +3 -0
  12. package/src/api/client.ts +285 -55
  13. package/src/api/config.ts +21 -0
  14. package/src/api/diagnose.test.ts +33 -2
  15. package/src/api/diagnose.ts +97 -3
  16. package/src/api/radarFeatures.render.test.tsx +33 -1
  17. package/src/api/radarFeatures.test.ts +47 -0
  18. package/src/api/radarFeatures.ts +41 -1
  19. package/src/api/rbac.settled.test.tsx +42 -0
  20. package/src/api/rbac.test.ts +18 -0
  21. package/src/api/rbac.ts +37 -7
  22. package/src/api/traffic.ts +9 -4
  23. package/src/api/usage-data.fixtures.ts +3 -1
  24. package/src/api/usage-data.test.tsx +134 -0
  25. package/src/api/usage-data.ts +35 -7
  26. package/src/api/workloadPodsPolling.test.ts +26 -0
  27. package/src/components/CloudConnectFlow.test.tsx +86 -0
  28. package/src/components/CloudConnectFlow.tsx +65 -27
  29. package/src/components/CloudFunnelButton.test.tsx +140 -5
  30. package/src/components/CloudFunnelButton.tsx +50 -9
  31. package/src/components/ConnectionErrorView.test.tsx +34 -0
  32. package/src/components/ConnectionErrorView.tsx +35 -11
  33. package/src/components/ContextSwitcher.tsx +5 -2
  34. package/src/components/SwitchAwareConnectionError.test.tsx +43 -0
  35. package/src/components/SwitchAwareConnectionError.tsx +85 -0
  36. package/src/components/application-evidence/ApplicationEvidenceAction.flow.test.tsx +234 -0
  37. package/src/components/application-evidence/ApplicationEvidenceAction.test.tsx +144 -0
  38. package/src/components/application-evidence/ApplicationEvidenceAction.tsx +218 -0
  39. package/src/components/capacity/CapacityDemand.tsx +3 -2
  40. package/src/components/capacity/demandSummary.test.ts +38 -0
  41. package/src/components/capacity/shared.tsx +12 -1
  42. package/src/components/cost/ApplicationCostTab.tsx +4 -0
  43. package/src/components/cost/CostTrendChart.tsx +2 -0
  44. package/src/components/cost/WorkloadCostTab.tsx +4 -0
  45. package/src/components/cost/source.test.ts +5 -0
  46. package/src/components/cost/source.ts +11 -0
  47. package/src/components/diagnose/AIMarkdown.tsx +4 -1
  48. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  49. package/src/components/diagnose/AgentControls.tsx +53 -6
  50. package/src/components/diagnose/AgentSetupNotice.test.tsx +17 -0
  51. package/src/components/diagnose/AgentSetupNotice.tsx +22 -4
  52. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  53. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  54. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  55. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  56. package/src/components/diagnose/AssessmentCard.tsx +39 -8
  57. package/src/components/diagnose/ContinueInAgentButton.mounted.test.tsx +182 -0
  58. package/src/components/diagnose/ContinueInAgentButton.test.tsx +128 -0
  59. package/src/components/diagnose/ContinueInAgentButton.tsx +303 -0
  60. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  61. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  62. package/src/components/diagnose/DiagnoseContext.tsx +272 -10
  63. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  64. package/src/components/diagnose/DiagnoseSurface.tsx +151 -134
  65. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  66. package/src/components/diagnose/ExampleInvestigationLink.tsx +20 -0
  67. package/src/components/diagnose/Home.test.tsx +208 -5
  68. package/src/components/diagnose/Home.tsx +187 -36
  69. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  70. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  71. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  72. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
  73. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  74. package/src/components/diagnose/InvestigationEvidenceSections.tsx +50 -23
  75. package/src/components/diagnose/InvestigationView.tsx +249 -54
  76. package/src/components/diagnose/LocalDiagnoseAction.history.test.tsx +450 -0
  77. package/src/components/diagnose/LocalDiagnoseAction.tsx +365 -39
  78. package/src/components/diagnose/NextStepJump.test.tsx +92 -0
  79. package/src/components/diagnose/NextStepJump.tsx +75 -0
  80. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  81. package/src/components/diagnose/QuestionComposer.tsx +495 -0
  82. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  83. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  84. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  85. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  86. package/src/components/diagnose/assessmentCopy.ts +5 -0
  87. package/src/components/diagnose/exampleInvestigation.events.json +191 -0
  88. package/src/components/diagnose/exampleInvestigation.loadFailure.test.tsx +94 -0
  89. package/src/components/diagnose/exampleInvestigation.test.tsx +248 -0
  90. package/src/components/diagnose/exampleInvestigation.ts +121 -0
  91. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  92. package/src/components/diagnose/investigationCase.test.tsx +9 -1
  93. package/src/components/diagnose/investigationCase.ts +33 -1
  94. package/src/components/diagnose/investigationEvidence/adapters/applicationFindings.test.ts +739 -0
  95. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  96. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +58 -2
  97. package/src/components/diagnose/investigationEvidence/adapters/issues.ts +9 -0
  98. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  99. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
  100. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
  101. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  102. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  103. package/src/components/diagnose/investigationEvidence/builder.ts +30 -0
  104. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  105. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  106. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  107. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  108. package/src/components/diagnose/investigationEvidence/observations.ts +121 -2
  109. package/src/components/diagnose/investigationEvidence/projection.test.ts +85 -3
  110. package/src/components/diagnose/investigationEvidence/types.ts +7 -0
  111. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  112. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  113. package/src/components/diagnose/investigationFocus.ts +132 -0
  114. package/src/components/diagnose/investigationState.ts +28 -0
  115. package/src/components/diagnose/lastInvestigation.test.ts +95 -0
  116. package/src/components/diagnose/lastInvestigation.ts +58 -0
  117. package/src/components/diagnose/launch.test.ts +125 -1
  118. package/src/components/diagnose/launch.ts +57 -10
  119. package/src/components/diagnose/parts.test.tsx +20 -0
  120. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  121. package/src/components/diagnose/questionSuggestions.ts +150 -0
  122. package/src/components/diagnose/storyParts.test.tsx +13 -0
  123. package/src/components/diagnose/target.test.ts +143 -2
  124. package/src/components/diagnose/target.ts +109 -7
  125. package/src/components/diagnose/testdata/story-runs.json +474 -0
  126. package/src/components/diagnose/toolCallLabel.test.ts +10 -4
  127. package/src/components/diagnose/verdictText.test.tsx +87 -0
  128. package/src/components/diagnose/verdictText.ts +68 -0
  129. package/src/components/execution/BatchExecutionView.tsx +24 -11
  130. package/src/components/execution/JobSetAdmission.test.tsx +42 -0
  131. package/src/components/execution/JobSetAdmission.tsx +18 -3
  132. package/src/components/execution/JobSetMemberComparison.tsx +2 -1
  133. package/src/components/execution/runState.test.ts +14 -0
  134. package/src/components/execution/runState.ts +8 -0
  135. package/src/components/gitops/GitOpsView.rollbackGate.test.tsx +202 -0
  136. package/src/components/gitops/GitOpsView.syncRequest.test.tsx +369 -0
  137. package/src/components/gitops/GitOpsView.tsx +86 -17
  138. package/src/components/gitops/RemoteDestinationCloudHint.tsx +2 -3
  139. package/src/components/gitops/destination-toast.test.ts +1 -1
  140. package/src/components/gitops/destination-toast.ts +2 -2
  141. package/src/components/home/ClusterHealthCard.tsx +13 -39
  142. package/src/components/home/HomeAgentBlock.test.tsx +141 -0
  143. package/src/components/home/HomeAgentBlock.tsx +103 -0
  144. package/src/components/home/HomeDiagramCard.tsx +47 -0
  145. package/src/components/home/HomeView.tsx +86 -47
  146. package/src/components/home/MCPSetupDialog.test.tsx +95 -5
  147. package/src/components/home/MCPSetupDialog.tsx +30 -5
  148. package/src/components/home/ProblemsPanel.investigate.test.tsx +171 -0
  149. package/src/components/home/ProblemsPanel.test.tsx +3 -1
  150. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  151. package/src/components/home/RadarVersionLine.tsx +3 -28
  152. package/src/components/home/TopologyPreview.test.tsx +73 -0
  153. package/src/components/home/TopologyPreview.tsx +120 -233
  154. package/src/components/home/TrafficSummary.test.tsx +63 -0
  155. package/src/components/home/TrafficSummary.tsx +135 -138
  156. package/src/components/home/mcpToolCatalog.ts +23 -10
  157. package/src/components/issues/IssuesPane.test.ts +11 -0
  158. package/src/components/issues/IssuesPane.tsx +15 -5
  159. package/src/components/issues/uncheckedSources.test.ts +20 -1
  160. package/src/components/issues/uncheckedSources.ts +18 -0
  161. package/src/components/kueue/KueuePendingPosition.tsx +35 -0
  162. package/src/components/kueue/useRelatedObjects.test.tsx +219 -0
  163. package/src/components/kueue/useRelatedReads.test.ts +56 -0
  164. package/src/components/kueue/useRelatedReads.ts +205 -0
  165. package/src/components/logs/MultiPodLogsTab.test.tsx +93 -0
  166. package/src/components/logs/MultiPodLogsTab.tsx +120 -0
  167. package/src/components/logs/PodLogsUnavailable.test.tsx +18 -0
  168. package/src/components/logs/PodLogsUnavailable.tsx +21 -0
  169. package/src/components/logs/RayClusterLogsTab.reselect.test.tsx +67 -0
  170. package/src/components/logs/RayClusterLogsTab.test.tsx +167 -0
  171. package/src/components/logs/RayClusterLogsTab.tsx +109 -0
  172. package/src/components/logs/ScheduledWorkloadLogsViewer.tsx +3 -2
  173. package/src/components/logs/rayClusterPods.ts +32 -0
  174. package/src/components/outageSince.test.ts +21 -0
  175. package/src/components/outageSince.ts +10 -0
  176. package/src/components/resource/PrometheusCharts.overlays.test.ts +12 -0
  177. package/src/components/resource/PrometheusCharts.tsx +3 -40
  178. package/src/components/resources/crd/CRDSchemaTab.test.tsx +28 -0
  179. package/src/components/resources/crd/CRDSchemaTab.tsx +13 -0
  180. package/src/components/resources/crd/host.tsx +14 -0
  181. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.test.tsx +27 -0
  182. package/src/components/resources/renderers/CustomResourceDefinitionRenderer.tsx +12 -0
  183. package/src/components/resources/renderers/JobAdmissionRenderers.test.tsx +4 -1
  184. package/src/components/resources/renderers/JobAdmissionRenderers.tsx +4 -3
  185. package/src/components/resources/renderers/KueueHostRenderers.test.tsx +117 -0
  186. package/src/components/resources/renderers/KueueQueueRenderers.test.tsx +97 -0
  187. package/src/components/resources/renderers/KueueQueueRenderers.tsx +139 -0
  188. package/src/components/resources/renderers/KueueWorkloadRenderer.test.tsx +7 -1
  189. package/src/components/resources/renderers/KueueWorkloadRenderer.tsx +47 -7
  190. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.test.tsx +67 -0
  191. package/src/components/resources/renderers/OpenTelemetryCollectorRenderer.tsx +31 -0
  192. package/src/components/resources/renderers/RayClusterRenderer.test.tsx +81 -3
  193. package/src/components/resources/renderers/RayClusterRenderer.tsx +19 -4
  194. package/src/components/traffic/TrafficView.tsx +3 -3
  195. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  196. package/src/components/ui/Omnibar.tsx +47 -3
  197. package/src/components/ui/RadarOmnibar.test.tsx +1 -0
  198. package/src/components/ui/RadarOmnibar.tsx +11 -0
  199. package/src/components/ui/command-items-crd.test.tsx +23 -0
  200. package/src/components/ui/command-items.ts +2 -1
  201. package/src/components/useContextSwitchFlow.test.tsx +61 -0
  202. package/src/components/useContextSwitchFlow.tsx +21 -4
  203. package/src/components/whats-new/WhatsNew.test.ts +10 -3
  204. package/src/components/whats-new/WhatsNew.tsx +5 -1
  205. package/src/components/whats-new/WhatsNewDialog.test.tsx +18 -4
  206. package/src/components/whats-new/releaseNotes.ts +136 -4
  207. package/src/components/workload/RelatedFindingsSection.test.tsx +126 -0
  208. package/src/components/workload/RelatedFindingsSection.tsx +80 -0
  209. package/src/components/workload/WorkloadView.test.ts +10 -1
  210. package/src/components/workload/WorkloadView.tsx +85 -98
  211. package/src/components/workload/issueResourceOpener.test.ts +20 -0
  212. package/src/components/workload/issueResourceOpener.ts +17 -0
  213. package/src/context/ConnectionContext.tsx +133 -60
  214. package/src/context/ConnectionProvider.retry.test.tsx +176 -0
  215. package/src/context/ContextSwitchContext.tsx +14 -1
  216. package/src/context/DiagnoseCustomization.tsx +3 -0
  217. package/src/context/clusterConnected.ts +10 -0
  218. package/src/contexts/CapabilitiesContext.tsx +6 -4
  219. package/src/hooks/useAgentSignin.test.tsx +190 -0
  220. package/src/hooks/useAgentSignin.ts +160 -0
  221. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
  222. package/src/hooks/useElementSize.ts +30 -0
  223. package/src/integrations/resourceHost.test.tsx +1 -0
  224. package/src/integrations/resourceHost.ts +5 -1
  225. package/src/integrations/resourceHosts.test.tsx +21 -4
  226. package/src/integrations/resourceHosts.tsx +12 -0
  227. package/src/main.tsx +5 -0
  228. package/src/utils/related-findings.ts +46 -0
@@ -0,0 +1,271 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { focusFromCase } from "./investigationFocus";
4
+ import type {
5
+ InvestigationCaseItem,
6
+ InvestigationCaseResolution,
7
+ } from "./investigationCase";
8
+
9
+ function item(
10
+ role: InvestigationCaseItem["role"],
11
+ tool: string,
12
+ args: Record<string, unknown>,
13
+ patch: Partial<InvestigationCaseItem["source"]> = {},
14
+ ): InvestigationCaseItem {
15
+ return {
16
+ index: 0,
17
+ role,
18
+ claim: "",
19
+ placement: "card",
20
+ source: {
21
+ id: `${tool}-${JSON.stringify(args)}`,
22
+ turnIndex: 0,
23
+ timelineIndex: 0,
24
+ stepId: "s",
25
+ tool,
26
+ args: JSON.stringify(args),
27
+ order: 0,
28
+ phase: "initial",
29
+ confirmedSuccess: true,
30
+ ...patch,
31
+ },
32
+ };
33
+ }
34
+
35
+ const resolution = (
36
+ items: InvestigationCaseItem[],
37
+ ): InvestigationCaseResolution => ({ items, ruledOut: [] });
38
+
39
+ describe("focusFromCase", () => {
40
+ it("names resources by the arguments Radar recorded, causes first", () => {
41
+ const focus = focusFromCase(
42
+ resolution([
43
+ item("symptom", "get_pod_logs", { namespace: "shop", name: "api-0" }),
44
+ item("cause", "get_resource", {
45
+ kind: "configmaps",
46
+ namespace: "shop",
47
+ name: "api-config",
48
+ }),
49
+ ]),
50
+ );
51
+ expect(focus).toEqual([
52
+ { kind: "ConfigMap", group: "", namespace: "shop", name: "api-config" },
53
+ { kind: "Pod", group: "", namespace: "shop", name: "api-0" },
54
+ ]);
55
+ });
56
+
57
+ it("names the cited issue's subject, not the resource the read was about", () => {
58
+ const cause = item("cause", "diagnose", {
59
+ kind: "Deployment",
60
+ namespace: "gl-netpol",
61
+ name: "web",
62
+ });
63
+ cause.observation = {
64
+ data: {
65
+ type: "issue",
66
+ relevance: "producer-related",
67
+ issue: {
68
+ kind: "NetworkPolicy",
69
+ group: "networking.k8s.io",
70
+ namespace: "gl-netpol",
71
+ name: "deny-all-ingress",
72
+ },
73
+ },
74
+ } as unknown as InvestigationCaseItem["observation"];
75
+ expect(focusFromCase(resolution([cause]))).toEqual([
76
+ {
77
+ kind: "NetworkPolicy",
78
+ group: "networking.k8s.io",
79
+ namespace: "gl-netpol",
80
+ name: "deny-all-ingress",
81
+ },
82
+ ]);
83
+ });
84
+
85
+ it("names a bound resource by its apiVersion group", () => {
86
+ const cause = item("cause", "list_resources", { kind: "configmaps" });
87
+ cause.observation = {
88
+ data: {
89
+ type: "resource",
90
+ resource: {
91
+ apiVersion: "apps/v1",
92
+ kind: "Deployment",
93
+ metadata: { namespace: "shop", name: "api" },
94
+ },
95
+ warnings: [],
96
+ },
97
+ } as unknown as InvestigationCaseItem["observation"];
98
+ expect(focusFromCase(resolution([cause]))).toEqual([
99
+ { kind: "Deployment", group: "apps", namespace: "shop", name: "api" },
100
+ ]);
101
+ });
102
+
103
+ it("lists a resource once when a read omitted the group the bound object has", () => {
104
+ const read = item("cause", "diagnose", {
105
+ kind: "deployment",
106
+ namespace: "shop",
107
+ name: "api",
108
+ });
109
+ const bound = item("cause", "get_resource", { kind: "deployments" });
110
+ bound.observation = {
111
+ data: {
112
+ type: "resource",
113
+ resource: {
114
+ apiVersion: "apps/v1",
115
+ kind: "Deployment",
116
+ metadata: { namespace: "shop", name: "api" },
117
+ },
118
+ warnings: [],
119
+ },
120
+ } as unknown as InvestigationCaseItem["observation"];
121
+ expect(focusFromCase(resolution([read, bound]))).toEqual([
122
+ { kind: "Deployment", group: "apps", namespace: "shop", name: "api" },
123
+ ]);
124
+ });
125
+
126
+ it("keeps same-named resources of different exact groups apart", () => {
127
+ const core = item("cause", "get_resource", {});
128
+ core.observation = {
129
+ data: {
130
+ type: "resource",
131
+ resource: {
132
+ apiVersion: "v1",
133
+ kind: "Service",
134
+ metadata: { namespace: "shop", name: "api" },
135
+ },
136
+ warnings: [],
137
+ },
138
+ } as unknown as InvestigationCaseItem["observation"];
139
+ const knative = item("symptom", "get_resource", {});
140
+ knative.observation = {
141
+ data: {
142
+ type: "resource",
143
+ resource: {
144
+ apiVersion: "serving.knative.dev/v1",
145
+ kind: "Service",
146
+ metadata: { namespace: "shop", name: "api" },
147
+ },
148
+ warnings: [],
149
+ },
150
+ } as unknown as InvestigationCaseItem["observation"];
151
+ expect(focusFromCase(resolution([core, knative]))).toHaveLength(2);
152
+ });
153
+
154
+ it("does not guess a resource from a read that searched every namespace", () => {
155
+ expect(
156
+ focusFromCase(
157
+ resolution([
158
+ item("cause", "get_events", { kind: "Deployment", name: "api" }),
159
+ ]),
160
+ ),
161
+ ).toEqual([]);
162
+ });
163
+
164
+ it("reads workload logs as the Deployment the tool defaults to", () => {
165
+ expect(
166
+ focusFromCase(
167
+ resolution([
168
+ item("symptom", "get_workload_logs", {
169
+ namespace: "shop",
170
+ name: "api",
171
+ }),
172
+ ]),
173
+ ),
174
+ ).toEqual([
175
+ { kind: "Deployment", group: "", namespace: "shop", name: "api" },
176
+ ]);
177
+ });
178
+
179
+ it("keeps the exact kind Radar recorded", () => {
180
+ const cause = item("cause", "get_resource", { kind: "podmetrics" });
181
+ cause.observation = {
182
+ data: {
183
+ type: "resource",
184
+ resource: {
185
+ apiVersion: "metrics.k8s.io/v1beta1",
186
+ kind: "PodMetrics",
187
+ metadata: { namespace: "shop", name: "api-0" },
188
+ },
189
+ warnings: [],
190
+ },
191
+ } as unknown as InvestigationCaseItem["observation"];
192
+ expect(focusFromCase(resolution([cause]))).toEqual([
193
+ {
194
+ kind: "PodMetrics",
195
+ group: "metrics.k8s.io",
196
+ namespace: "shop",
197
+ name: "api-0",
198
+ },
199
+ ]);
200
+ });
201
+
202
+ it("names the pod a cited log stream came from", () => {
203
+ const symptom = item("symptom", "diagnose", {
204
+ kind: "Deployment",
205
+ namespace: "shop",
206
+ name: "api",
207
+ });
208
+ symptom.observation = {
209
+ data: {
210
+ type: "logs",
211
+ pod: "api-123",
212
+ namespace: "shop",
213
+ previous: false,
214
+ },
215
+ } as unknown as InvestigationCaseItem["observation"];
216
+ expect(focusFromCase(resolution([symptom]))).toEqual([
217
+ { kind: "Pod", group: "", namespace: "shop", name: "api-123" },
218
+ ]);
219
+ });
220
+
221
+ it("spells an agent's lowercase kind the Kubernetes way", () => {
222
+ expect(
223
+ focusFromCase(
224
+ resolution([
225
+ item("cause", "diagnose", {
226
+ kind: "deployment",
227
+ namespace: "gl-missing-cm",
228
+ name: "checkout",
229
+ }),
230
+ ]),
231
+ ),
232
+ ).toEqual([
233
+ {
234
+ kind: "Deployment",
235
+ group: "",
236
+ namespace: "gl-missing-cm",
237
+ name: "checkout",
238
+ },
239
+ ]);
240
+ });
241
+
242
+ it("ignores broad reads, context, failed reads and repeats", () => {
243
+ const focus = focusFromCase(
244
+ resolution([
245
+ item("cause", "search", { query: "checkout" }),
246
+ item("context", "get_resource", { kind: "Pod", name: "x" }),
247
+ item(
248
+ "cause",
249
+ "get_resource",
250
+ { kind: "Pod", namespace: "shop", name: "denied" },
251
+ { confirmedSuccess: false },
252
+ ),
253
+ item("cause", "diagnose", {
254
+ kind: "Deployment",
255
+ group: "apps",
256
+ namespace: "shop",
257
+ name: "api",
258
+ }),
259
+ item("symptom", "get_events", {
260
+ kind: "Deployment",
261
+ group: "apps",
262
+ namespace: "shop",
263
+ name: "api",
264
+ }),
265
+ ]),
266
+ );
267
+ expect(focus).toEqual([
268
+ { kind: "Deployment", group: "apps", namespace: "shop", name: "api" },
269
+ ]);
270
+ });
271
+ });
@@ -0,0 +1,132 @@
1
+ import type {
2
+ InvestigationCaseItem,
3
+ InvestigationCaseResolution,
4
+ } from "./investigationCase";
5
+ import {
6
+ investigationEvidenceSubjectRef,
7
+ investigationSourceArgs,
8
+ } from "./investigationEvidence/identity";
9
+ import {
10
+ canonicalKind,
11
+ runTargetKey,
12
+ type InvestigationTargetIdentity,
13
+ } from "./target";
14
+
15
+ // Reads that are about exactly the resource their arguments name. A broad
16
+ // read (a search, a namespace listing) proves nothing about which resource
17
+ // mattered, however its rows are cited.
18
+ const SINGLE_RESOURCE_TOOLS = new Set([
19
+ "diagnose",
20
+ "get_resource",
21
+ "get_events",
22
+ "get_neighborhood",
23
+ "get_workload_logs",
24
+ "get_pod_logs",
25
+ ]);
26
+
27
+ const NAMESPACED_ONLY_TOOLS = new Set([
28
+ "get_events",
29
+ "get_pod_logs",
30
+ "get_workload_logs",
31
+ ]);
32
+
33
+ // The resources a question-only assessment came to rest on, causes first.
34
+ // Each is named by what Radar produced, never by what the agent wrote: the
35
+ // object the citation bound to, or else the resource a single-resource read
36
+ // was asked about.
37
+ export function focusFromCase(
38
+ investigationCase: InvestigationCaseResolution | undefined,
39
+ max = 3,
40
+ ): InvestigationTargetIdentity[] {
41
+ if (!investigationCase) return [];
42
+ const items = investigationCase.items
43
+ .filter((item) => item.role === "cause" || item.role === "symptom")
44
+ .sort((a, b) => Number(b.role === "cause") - Number(a.role === "cause"));
45
+ const focus: (InvestigationTargetIdentity & { exact: boolean })[] = [];
46
+ for (const item of items) {
47
+ const bound = boundResource(item);
48
+ const resource = bound ?? readResource(item);
49
+ if (!resource) continue;
50
+ // A read's arguments often leave out a built-in group the bound object
51
+ // carries (deployment vs apps/Deployment): the same resource either way,
52
+ // named by the exact identity whichever arrives first.
53
+ const same = focus.findIndex(
54
+ (seen) =>
55
+ sameResource(seen, resource) &&
56
+ (seen.group === resource.group ||
57
+ (!seen.exact && !seen.group) ||
58
+ (!bound && !resource.group)),
59
+ );
60
+ if (same >= 0) {
61
+ if (bound && !focus[same].exact) focus[same] = { ...bound, exact: true };
62
+ continue;
63
+ }
64
+ if (focus.length >= max) continue;
65
+ focus.push({ ...resource, exact: !!bound });
66
+ }
67
+ return focus.map(({ kind, group, namespace, name }) => ({
68
+ kind,
69
+ group,
70
+ namespace,
71
+ name,
72
+ }));
73
+ }
74
+
75
+ function sameResource(
76
+ a: InvestigationTargetIdentity,
77
+ b: InvestigationTargetIdentity,
78
+ ): boolean {
79
+ return (
80
+ a.namespace === b.namespace &&
81
+ a.name === b.name &&
82
+ runTargetKey(a.kind, "", "", "") === runTargetKey(b.kind, "", "", "")
83
+ );
84
+ }
85
+
86
+ // What the citation bound to, exactly as Radar recorded it.
87
+ function boundResource(
88
+ item: InvestigationCaseItem,
89
+ ): InvestigationTargetIdentity | undefined {
90
+ const data = item.observation?.data;
91
+ const ref = data ? investigationEvidenceSubjectRef(data) : undefined;
92
+ if (!ref?.kind || !ref.name) return undefined;
93
+ return {
94
+ kind: ref.kind,
95
+ group: ref.group ?? "",
96
+ namespace: ref.namespace ?? "",
97
+ name: ref.name,
98
+ };
99
+ }
100
+
101
+ function readResource(
102
+ item: InvestigationCaseItem,
103
+ ): InvestigationTargetIdentity | undefined {
104
+ const { source } = item;
105
+ if (!source.confirmedSuccess || !SINGLE_RESOURCE_TOOLS.has(source.tool)) {
106
+ return undefined;
107
+ }
108
+ const args = investigationSourceArgs(source);
109
+ const name = typeof args?.name === "string" ? args.name : "";
110
+ const kind =
111
+ source.tool === "get_pod_logs"
112
+ ? "Pod"
113
+ : typeof args?.kind === "string" && args.kind
114
+ ? args.kind
115
+ : source.tool === "get_workload_logs"
116
+ ? "Deployment"
117
+ : "";
118
+ const namespace = typeof args?.namespace === "string" ? args.namespace : "";
119
+ if (!name || !kind) return undefined;
120
+ // These reads search every namespace when given none, so their arguments
121
+ // alone don't say which resource they were about.
122
+ if (!namespace && NAMESPACED_ONLY_TOOLS.has(source.tool)) return undefined;
123
+ const group = typeof args?.group === "string" ? args.group : "";
124
+ // Agents spell kinds every way kubectl accepts: deployment, deployments,
125
+ // Deployment. The server canonicalizes the group when a run starts.
126
+ return {
127
+ kind: canonicalKind(kind, group),
128
+ group,
129
+ namespace,
130
+ name,
131
+ };
132
+ }
@@ -800,6 +800,34 @@ export function canStopInvestigation(
800
800
  );
801
801
  }
802
802
 
803
+ // The hand-off resumes the agent's own session, so it waits until no turn is
804
+ // writing to that session. A finished transcript outranks a run summary that
805
+ // still says running, as for Stop; stopping does not, because Stop writes its
806
+ // terminal frame before the agent process has exited.
807
+ export function canContinueInOwnAgent(input: {
808
+ run: RunSummary;
809
+ busy: boolean;
810
+ requestPending: boolean;
811
+ gone: boolean;
812
+ streamReady: boolean;
813
+ verificationPending: boolean;
814
+ latestTurnStatus?: Turn["status"];
815
+ }): boolean {
816
+ const { run, latestTurnStatus } = input;
817
+ const transcriptTerminal =
818
+ latestTurnStatus === "done" || latestTurnStatus === "error";
819
+ return (
820
+ input.streamReady &&
821
+ !input.busy &&
822
+ !input.requestPending &&
823
+ !input.verificationPending &&
824
+ !input.gone &&
825
+ run.status !== "stopping" &&
826
+ latestTurnStatus !== "running" &&
827
+ (transcriptTerminal || run.status !== "running")
828
+ );
829
+ }
830
+
803
831
  export function canContinueInvestigation(
804
832
  run: RunSummary,
805
833
  latestTurnStatus?: Turn["status"],
@@ -0,0 +1,95 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import type { RunSummary } from "../../api/diagnose";
4
+ import {
5
+ LAST_INVESTIGATION_MAX_AGE_MS,
6
+ lastInvestigations,
7
+ sameObject,
8
+ } from "./lastInvestigation";
9
+ import { runTargetKey } from "./target";
10
+
11
+ const now = Date.parse("2026-11-02T12:00:00Z");
12
+ const hoursAgo = (h: number) => new Date(now - h * 3600_000).toISOString();
13
+ const key = runTargetKey("Deployment", "shop", "cart", "apps");
14
+
15
+ function run(over: Partial<RunSummary>): RunSummary {
16
+ return {
17
+ id: "r1",
18
+ kind: "Deployment",
19
+ group: "apps",
20
+ namespace: "shop",
21
+ name: "cart",
22
+ context: "cluster-a",
23
+ status: "done",
24
+ preview: "Pods crash on a bad flag",
25
+ assessedAt: hoursAgo(2),
26
+ createdAt: hoursAgo(3),
27
+ updatedAt: hoursAgo(1),
28
+ ...over,
29
+ };
30
+ }
31
+
32
+ describe("lastInvestigations", () => {
33
+ it("picks the newest assessment of the resource on the cluster in use", () => {
34
+ const got = lastInvestigations(
35
+ [
36
+ run({ id: "old", assessedAt: hoursAgo(30) }),
37
+ run({ id: "new", assessedAt: hoursAgo(2), preview: "Healthy" }),
38
+ run({
39
+ id: "other-cluster",
40
+ context: "cluster-b",
41
+ assessedAt: hoursAgo(1),
42
+ }),
43
+ ],
44
+ "cluster-a",
45
+ now,
46
+ );
47
+ expect(got.get(key)).toMatchObject({ id: "new", preview: "Healthy" });
48
+ });
49
+
50
+ it("counts a run made stale by a cluster switch", () => {
51
+ const got = lastInvestigations(
52
+ [run({ status: "stale" })],
53
+ "cluster-a",
54
+ now,
55
+ );
56
+ expect(got.get(key)?.id).toBe("r1");
57
+ });
58
+
59
+ it.each([
60
+ ["a live run", { status: "running" as const }],
61
+ [
62
+ "a question about no resource",
63
+ { name: "", question: "why is checkout slow?" },
64
+ ],
65
+ ["a run with no dated assessment", { assessedAt: undefined }],
66
+ [
67
+ "an assessment past the cutoff",
68
+ {
69
+ assessedAt: new Date(
70
+ now - LAST_INVESTIGATION_MAX_AGE_MS - 1,
71
+ ).toISOString(),
72
+ },
73
+ ],
74
+ ])("skips %s", (_, over) => {
75
+ expect(lastInvestigations([run(over)], "cluster-a", now).size).toBe(0);
76
+ });
77
+
78
+ it("matches nothing until the cluster in use is known", () => {
79
+ expect(lastInvestigations([run({})], undefined, now).size).toBe(0);
80
+ });
81
+ });
82
+
83
+ describe("sameObject", () => {
84
+ const last = { id: "r1", preview: "x", assessedAt: hoursAgo(2) };
85
+ it("rejects an object created after the assessment", () => {
86
+ expect(sameObject(last, hoursAgo(1))).toBe(false);
87
+ });
88
+ it("accepts an object recreated mid-run that the assessment saw", () => {
89
+ expect(sameObject(last, hoursAgo(2.5))).toBe(true);
90
+ });
91
+ it("accepts an older object, or one whose creation time is unknown", () => {
92
+ expect(sameObject(last, hoursAgo(48))).toBe(true);
93
+ expect(sameObject(last, undefined)).toBe(true);
94
+ });
95
+ });
@@ -0,0 +1,58 @@
1
+ import type { RunSummary } from "../../api/diagnose";
2
+ import { isQuestionOnly, runTargetKey } from "./target";
3
+
4
+ // Past this age a verdict describes the cluster as it was, not as it is, so the
5
+ // resource stops pointing at it. History still lists it.
6
+ export const LAST_INVESTIGATION_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
7
+
8
+ export interface LastInvestigation {
9
+ id: string;
10
+ preview: string;
11
+ assessedAt: string;
12
+ }
13
+
14
+ // The newest assessment of each resource on the cluster in use. Only runs the
15
+ // server dated with assessedAt qualify: their preview is the assessment
16
+ // Findings shows, not a later answer. Stale runs count, since switching
17
+ // clusters marks every run stale.
18
+ export function lastInvestigations(
19
+ runs: readonly RunSummary[],
20
+ context: string | undefined,
21
+ now: number,
22
+ ): Map<string, LastInvestigation> {
23
+ const out = new Map<string, LastInvestigation>();
24
+ if (!context) return out;
25
+ for (const r of runs) {
26
+ if (
27
+ isQuestionOnly(r) ||
28
+ r.status === "running" ||
29
+ r.status === "stopping" ||
30
+ r.context !== context ||
31
+ !r.assessedAt ||
32
+ !r.preview
33
+ )
34
+ continue;
35
+ const assessed = Date.parse(r.assessedAt);
36
+ if (!(now - assessed <= LAST_INVESTIGATION_MAX_AGE_MS)) continue;
37
+ const key = runTargetKey(r.kind, r.namespace, r.name, r.group);
38
+ const prev = out.get(key);
39
+ if (prev && Date.parse(prev.assessedAt) >= assessed) continue;
40
+ out.set(key, {
41
+ id: r.id,
42
+ preview: r.preview,
43
+ assessedAt: r.assessedAt,
44
+ });
45
+ }
46
+ return out;
47
+ }
48
+
49
+ // Whether the object on screen is the one the assessment describes. Without a
50
+ // UID the creation time is the only tell: an object created after the
51
+ // assessment was recreated since. Unknown creation time can't rule it out.
52
+ export function sameObject(
53
+ last: LastInvestigation,
54
+ objectCreatedAt: string | undefined,
55
+ ): boolean {
56
+ if (!objectCreatedAt) return true;
57
+ return !(Date.parse(objectCreatedAt) > Date.parse(last.assessedAt));
58
+ }