@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
@@ -29,15 +29,22 @@ import {
29
29
  recordConsent,
30
30
  DiagnoseError,
31
31
  investigationRefusal,
32
+ investigationCapacity,
32
33
  } from "../../api/diagnose";
33
34
  import { getApiBase } from "../../api/config";
35
+ import { useContexts } from "../../api/client";
34
36
  import {
35
37
  type InvestigationRefusal,
36
38
  type RunSummary,
37
39
  type AgentInfo,
38
40
  type ExecutionProfile,
39
41
  } from "../../api/diagnose";
40
- import { runTargetKey } from "./target";
42
+ import { isQuestionOnly, runTargetKey } from "./target";
43
+ import {
44
+ type LastInvestigation,
45
+ lastInvestigations,
46
+ } from "./lastInvestigation";
47
+ import { isExampleInvestigation } from "./exampleInvestigation";
41
48
  import { knownKindForPluralWithGroup } from "../../utils/navigation";
42
49
 
43
50
  export interface Target {
@@ -54,9 +61,45 @@ export interface Target {
54
61
  * the consent-deferred path replays one object — a parallel "was it fresh?"
55
62
  * state is a thing that can fall out of sync with the target it describes. */
56
63
  fresh?: boolean;
64
+ /** The engineer's question. With an empty kind and name, the run is about
65
+ * the question alone. */
66
+ question?: string;
67
+ namespaces?: string[];
68
+ lookBack?: string;
69
+ /** When the question was first asked, for a run that re-runs or narrows
70
+ * an earlier one; absent means now. */
71
+ askedAt?: string;
72
+ /** Started from the question composer, which hands its draft over to the
73
+ * start: a start that never becomes a run gives the question back. */
74
+ fromComposer?: boolean;
75
+ /** The cluster the start was made in; set when it is opened. */
76
+ context?: string;
57
77
  }
58
78
  export type DiagnoseView = "home" | "investigation";
59
79
 
80
+ // What the question composer opens with when something hands it a start:
81
+ // the resource to pin, the words typed so far. seq makes a second hand-off
82
+ // with the same content still land.
83
+ export interface QuestionDraft {
84
+ seq: number;
85
+ text?: string;
86
+ pin?: { kind: string; group: string; namespace: string; name: string };
87
+ namespaces?: string[];
88
+ lookBack?: string;
89
+ /** A question handed back because its start never became a run: a
90
+ * composer already holding other words keeps them. */
91
+ restore?: boolean;
92
+ /** Open the resource picker with it: choose the resource to ask about. */
93
+ pickResource?: boolean;
94
+ /** When the handed-over question was first asked; kept while its words are. */
95
+ askedAt?: string;
96
+ /** The cluster the pin and namespaces were chosen in. */
97
+ context?: string;
98
+ /** A hand-off that brings no words of its own (Ask about a resource):
99
+ * whatever the engineer already wrote stays. */
100
+ keepWords?: boolean;
101
+ }
102
+
60
103
  // Setup readiness of local AI investigations, derived from the agents API:
61
104
  // - "ready": an agent is installed and the engine is running (available)
62
105
  // - "needs-install": the feature is supported here but no agent CLI is installed
@@ -87,6 +130,7 @@ interface DiagnoseCtx {
87
130
  cliOverride: boolean;
88
131
  agentLabel: string; // label of the selected agent, e.g. "Claude Code"
89
132
  hosted: boolean; // selected agent runs on the host's backend, not this machine
133
+ questions: boolean; // the selected agent's backend opens a run from a question
90
134
  agents: AgentInfo[]; // supported agents detected on PATH (for the picker)
91
135
  selectedAgent: string; // name of the chosen backend ("claude"/"codex")
92
136
  setSelectedAgent: (name: string) => void;
@@ -103,10 +147,15 @@ interface DiagnoseCtx {
103
147
  runsLoadFailed: boolean; // latest runs fetch failed (poll keeps retrying)
104
148
  historyDegraded: boolean; // persistence broke — history won't survive a restart
105
149
  needsConsent: boolean; // a start is pending the one-time consent
150
+ pendingTarget: Target | null; // what that pending start is about
106
151
  startError: string | null;
107
152
  // The host's refusal behind startError, when it sent one, so the surface can
108
153
  // offer the host's action beside the message.
109
154
  startRefusal: InvestigationRefusal | null;
155
+ // Set when the start failed because every investigation slot is taken: the
156
+ // start to retry once one is free, how many run at once, and the cluster
157
+ // the start was refused in.
158
+ startCapacity: StartCapacity | null;
110
159
  // Kept apart from startError: the consent card renders this as "why your
111
160
  // approval was refused", and a run-start failure landing in the same slot
112
161
  // would be read as exactly that — the two paths don't share a lifecycle.
@@ -114,6 +163,12 @@ interface DiagnoseCtx {
114
163
  openInvestigation: (t: Target) => void;
115
164
  openRun: (id: string) => void;
116
165
  openHome: () => void;
166
+ // Opens Home's question composer with a resource pinned or words typed.
167
+ openQuestion: (draft: Omit<QuestionDraft, "seq">) => void;
168
+ // Keeps the composer's unsent content when it unmounts, without handing it
169
+ // back to the composer as a new start.
170
+ saveQuestionDraft: (draft: Omit<QuestionDraft, "seq">) => void;
171
+ questionDraft: QuestionDraft | null;
117
172
  openWorkspace: (runID?: string | null) => void;
118
173
  restoreWorkspace: () => void;
119
174
  canRestoreWorkspace: boolean;
@@ -145,7 +200,13 @@ interface DiagnoseLayoutCtx {
145
200
  panelBounds: { min: number; max: number };
146
201
  panelWidthKey: string;
147
202
  runningKeys: ReadonlySet<string>; // resources with a live investigation (see runTargetKey)
203
+ // The live run behind each running key, so "view it" opens that run rather
204
+ // than starting another: a question someone asked about the resource
205
+ // doesn't stand in for a fresh resource start.
206
+ runningRunIds: ReadonlyMap<string, string>;
148
207
  runningCount: number;
208
+ // The newest recent assessment of each resource on the cluster in use.
209
+ lastInvestigations: ReadonlyMap<string, LastInvestigation>;
149
210
  }
150
211
 
151
212
  const Ctx = createContext<DiagnoseCtx | null>(null);
@@ -232,6 +293,20 @@ export function agentLabelFor(name: string, fallbackLabel?: string): string {
232
293
  return AGENT_LABELS[name] || fallbackLabel || name || "your AI agent";
233
294
  }
234
295
 
296
+ export interface StartCapacity {
297
+ target: Target;
298
+ limit: number;
299
+ context?: string;
300
+ }
301
+
302
+ function startCapacity(
303
+ error: unknown,
304
+ target: Target,
305
+ ): StartCapacity | undefined {
306
+ const capacity = investigationCapacity(error);
307
+ return capacity ? { target, ...capacity } : undefined;
308
+ }
309
+
235
310
  // openDiagnoseSettings opens the Settings dialog (App.tsx listens for this DOM
236
311
  // event) — the canonical home for AI investigation config.
237
312
  export function openDiagnoseSettings() {
@@ -469,12 +544,56 @@ function RoutedDiagnoseProvider({
469
544
  );
470
545
  const [runs, setRuns] = useState<RunSummary[]>([]);
471
546
  const [runsLoaded, setRunsLoaded] = useState(false);
547
+ const [listedAt, setListedAt] = useState(() => Date.now());
472
548
  const [runsLoadFailed, setRunsLoadFailed] = useState(false);
473
549
  const [historyDegraded, setHistoryDegraded] = useState(false);
474
550
  const [pendingTarget, setPendingTarget] = useState<Target | null>(null);
551
+ // The question composer's content outside the composer, so a hand-off can
552
+ // fill it and a start that never became a run (consent cancelled, a refused
553
+ // start) hands the engineer's words back instead of losing them.
554
+ const [questionDraft, setQuestionDraft] = useState<QuestionDraft | null>(
555
+ null,
556
+ );
557
+ const consentApprovalRef = useRef(0);
558
+ // The cluster in use now. A start waiting on consent names things in the
559
+ // cluster it was made in; if the cluster changes first, it is dropped
560
+ // rather than run against same-named things in the new one.
561
+ const { data: contexts } = useContexts();
562
+ const currentContext = contexts?.find((context) => context.isCurrent)?.name;
563
+ const currentContextRef = useRef(currentContext);
564
+ currentContextRef.current = currentContext;
565
+ // A question that never became a run goes back to the composer, unless the
566
+ // engineer has written something else there since.
567
+ const giveQuestionBack = useCallback((t: Target) => {
568
+ if (!t.fromComposer || !t.question) return;
569
+ setQuestionDraft((previous) =>
570
+ previous?.text?.trim()
571
+ ? previous
572
+ : {
573
+ seq: (previous?.seq ?? 0) + 1,
574
+ text: t.question,
575
+ pin: t.name
576
+ ? {
577
+ kind: t.kind,
578
+ group: t.group,
579
+ namespace: t.namespace,
580
+ name: t.name,
581
+ }
582
+ : undefined,
583
+ // An empty list is an explicit "all namespaces", not "follow the
584
+ // header": hand it back as it was.
585
+ namespaces: t.namespaces,
586
+ lookBack: t.lookBack,
587
+ askedAt: t.askedAt,
588
+ context: t.context,
589
+ restore: true,
590
+ },
591
+ );
592
+ }, []);
475
593
  const [startFailure, setStartFailure] = useState<{
476
594
  message: string;
477
595
  refusal: InvestigationRefusal | null;
596
+ capacity?: StartCapacity;
478
597
  } | null>(null);
479
598
  const [consentError, setConsentError] = useState<string | null>(null);
480
599
  const [width, setWidth] = useState<number>(() => {
@@ -632,10 +751,17 @@ function RoutedDiagnoseProvider({
632
751
  return () => window.removeEventListener("resize", onResize);
633
752
  }, []);
634
753
 
754
+ // Fetches overlap (polling, focus, a cluster switch). One that started
755
+ // before the list last changed is dropped, or an older snapshot could
756
+ // restore cleared runs; a slow fetch still lands if nothing newer did.
757
+ const listSeqRef = useRef(0);
758
+ const appliedListSeqRef = useRef(0);
635
759
  const refreshRuns = useCallback(async () => {
636
760
  if (!available) return;
761
+ const seq = ++listSeqRef.current;
637
762
  try {
638
763
  const r = await listRuns();
764
+ if (seq < appliedListSeqRef.current) return;
639
765
  const focusedID = activeRunIdRef.current;
640
766
  let focusedRun: RunSummary | null = null;
641
767
  let retainFocusedSnapshot = false;
@@ -644,7 +770,11 @@ function RoutedDiagnoseProvider({
644
770
  : undefined;
645
771
  if (focusedID && listedFocusedRun) {
646
772
  unavailableRunIDsRef.current.delete(focusedID);
647
- } else if (focusedID && !unavailableRunIDsRef.current.has(focusedID)) {
773
+ } else if (
774
+ focusedID &&
775
+ !isExampleInvestigation(focusedID) &&
776
+ !unavailableRunIDsRef.current.has(focusedID)
777
+ ) {
648
778
  try {
649
779
  // A stable deep link can target a retained run older than the bounded
650
780
  // history page. Refresh it directly too: its status and capabilities
@@ -660,6 +790,9 @@ function RoutedDiagnoseProvider({
660
790
  retainFocusedSnapshot = !unavailable;
661
791
  }
662
792
  }
793
+ if (seq < appliedListSeqRef.current) return;
794
+ appliedListSeqRef.current = seq;
795
+ setListedAt(Date.now());
663
796
  setRuns((prev) => {
664
797
  let nextRuns = r.runs;
665
798
  if (focusedRun) nextRuns = [focusedRun, ...nextRuns];
@@ -686,6 +819,7 @@ function RoutedDiagnoseProvider({
686
819
  setRunsLoadFailed(false);
687
820
  setHistoryDegraded(!!r.historyDegraded);
688
821
  } catch {
822
+ if (seq < appliedListSeqRef.current) return;
689
823
  // Leave runsLoaded false (a missing-run verdict needs a real list) but
690
824
  // record the failure so the panel can say "retrying" instead of
691
825
  // pretending nothing happened. The 4s poll keeps retrying while open.
@@ -723,18 +857,57 @@ function RoutedDiagnoseProvider({
723
857
  // A content-stable signature of the resources with a live investigation,
724
858
  // so per-resource Investigate buttons only re-render when their live targets
725
859
  // change.
860
+ // A plain resource run sorts after a question about the same resource, so
861
+ // it is the one a key maps to when both are live.
862
+ // A local run names the kubeconfig context it ran in, so a same-named
863
+ // resource on another cluster isn't it. A hosted list is already one
864
+ // cluster's and labels it differently. Until the cluster in use is known, a
865
+ // live run can't be ruled out by it.
866
+ const scopeByContext = !hosted && !!currentContext;
726
867
  const runningSig = runningRuns
727
- .map((r) => runTargetKey(r.kind, r.namespace, r.name, r.group))
868
+ .filter(
869
+ (r) =>
870
+ !isQuestionOnly(r) && (!scopeByContext || r.context === currentContext),
871
+ )
872
+ .map(
873
+ (r) =>
874
+ `${runTargetKey(r.kind, r.namespace, r.name, r.group)}\t${r.question ? 0 : 1}\t${r.id}`,
875
+ )
728
876
  .sort()
729
- // resourceKey itself is pipe-delimited; newlines cannot occur in a
730
- // Kubernetes group, Kind, namespace, or name.
877
+ // resourceKey itself is pipe-delimited; newlines and tabs cannot occur in
878
+ // a Kubernetes group, Kind, namespace, or name.
731
879
  .join("\n");
732
- const runningKeys = useMemo(
733
- () => new Set(runningSig ? runningSig.split("\n") : []),
880
+ const runningRunIds = useMemo(
881
+ () =>
882
+ new Map(
883
+ (runningSig ? runningSig.split("\n") : []).map((line) => {
884
+ const [key, , id] = line.split("\t");
885
+ return [key, id] as const;
886
+ }),
887
+ ),
734
888
  [runningSig],
735
889
  );
890
+ const runningKeys = useMemo(
891
+ () => new Set(runningRunIds.keys()),
892
+ [runningRunIds],
893
+ );
736
894
  const runningCount = runningRuns.length;
737
895
  const hasRunning = runningCount > 0;
896
+ // The clock the cutoff reads moves on each fetch and hourly, so an entry
897
+ // ages out while nothing polls.
898
+ useEffect(() => {
899
+ const t = setInterval(() => setListedAt(Date.now()), 60 * 60 * 1000);
900
+ return () => clearInterval(t);
901
+ }, []);
902
+ // Serialized so the buttons re-render only when an entry changes, not on
903
+ // every poll that returns a fresh array.
904
+ const lastSig = JSON.stringify(
905
+ hosted ? [] : [...lastInvestigations(runs, currentContext, listedAt)],
906
+ );
907
+ const lastInvestigationsByKey = useMemo(
908
+ () => new Map<string, LastInvestigation>(JSON.parse(lastSig)),
909
+ [lastSig],
910
+ );
738
911
 
739
912
  // Keep the run list (statuses, new background runs) fresh while the surface is open
740
913
  // OR while any investigation is still running — so the button indicator stays live
@@ -748,6 +921,22 @@ function RoutedDiagnoseProvider({
748
921
  return () => clearInterval(t);
749
922
  }, [open, available, hasRunning, refreshRuns]);
750
923
 
924
+ // A resource shows its last investigation without the panel open, so the
925
+ // list also catches up when the window comes back (another tab's run, a
926
+ // cleared history, a failed first fetch) and when the cluster changes.
927
+ useEffect(() => {
928
+ if (!available) return;
929
+ window.addEventListener("focus", refreshRuns);
930
+ return () => window.removeEventListener("focus", refreshRuns);
931
+ }, [available, refreshRuns]);
932
+ const listedContextRef = useRef(currentContext);
933
+ useEffect(() => {
934
+ if (listedContextRef.current === currentContext) return;
935
+ const switched = listedContextRef.current !== undefined;
936
+ listedContextRef.current = currentContext;
937
+ if (switched) refreshRuns();
938
+ }, [currentContext, refreshRuns]);
939
+
751
940
  const consentedRef = useRef(consented);
752
941
  consentedRef.current = consented;
753
942
 
@@ -780,18 +969,24 @@ function RoutedDiagnoseProvider({
780
969
  // fetched; refresh it so the picker shows what's installed now.
781
970
  void recheckAgents();
782
971
  if (seq !== startSeqRef.current) return;
972
+ giveQuestionBack(t);
783
973
  setStartFailure({
784
974
  message:
785
975
  e instanceof DiagnoseError
786
976
  ? e.message
787
977
  : "Couldn't start the investigation.",
788
978
  refusal: investigationRefusal(e),
979
+ capacity: startCapacity(e, t),
789
980
  });
790
981
  });
791
982
  };
792
983
 
793
984
  const openInvestigation = useCallback(
794
- (t: Target) => {
985
+ (opened: Target) => {
986
+ const t = {
987
+ ...opened,
988
+ context: opened.context ?? currentContextRef.current,
989
+ };
795
990
  setStartFailure(null);
796
991
  setConsentError(null);
797
992
  setOpen(true);
@@ -802,6 +997,7 @@ function RoutedDiagnoseProvider({
802
997
  "Radar can’t run this agent with a verified execution profile.",
803
998
  refusal: null,
804
999
  });
1000
+ giveQuestionBack(t);
805
1001
  setView("investigation");
806
1002
  return;
807
1003
  }
@@ -813,16 +1009,20 @@ function RoutedDiagnoseProvider({
813
1009
  setView("investigation");
814
1010
  startRunRef.current(t);
815
1011
  },
816
- [consentSurface, hosted],
1012
+ [consentSurface, hosted, giveQuestionBack],
817
1013
  );
818
1014
  const openRun = useCallback(
819
1015
  (id: string) => {
820
1016
  unavailableRunIDsRef.current.delete(id);
1017
+ // A start still in flight no longer owns the pane: its refusal must not
1018
+ // replace the run the user just chose.
1019
+ startSeqRef.current++;
821
1020
  setStartFailure(null);
822
1021
  setActiveRunId(id);
823
1022
  setView("investigation");
824
1023
  setOpen(true);
825
1024
  writeFocusedRunID(id, true);
1025
+ if (isExampleInvestigation(id)) return;
826
1026
  // A Fleet issue can point at a retained automatic run older than the
827
1027
  // bounded history page. Resolve the exact id instead of waiting for list.
828
1028
  getRun(id)
@@ -917,6 +1117,7 @@ function RoutedDiagnoseProvider({
917
1117
  setActiveRunId(id);
918
1118
  setView("investigation");
919
1119
  setOpen(true);
1120
+ if (isExampleInvestigation(id)) return;
920
1121
  getRun(id)
921
1122
  .then(updateRunSummary)
922
1123
  .catch((error) => {
@@ -950,6 +1151,28 @@ function RoutedDiagnoseProvider({
950
1151
  setOpen(true);
951
1152
  writeFocusedRunID(null, false);
952
1153
  }, [writeFocusedRunID]);
1154
+ const openQuestion = useCallback(
1155
+ (draft: Omit<QuestionDraft, "seq">) => {
1156
+ setQuestionDraft((previous) =>
1157
+ draft.text === undefined
1158
+ ? {
1159
+ ...draft,
1160
+ text: previous?.text,
1161
+ askedAt: previous?.askedAt,
1162
+ keepWords: true,
1163
+ seq: (previous?.seq ?? 0) + 1,
1164
+ }
1165
+ : { ...draft, seq: (previous?.seq ?? 0) + 1 },
1166
+ );
1167
+ openHome();
1168
+ },
1169
+ [openHome],
1170
+ );
1171
+ const saveQuestionDraft = useCallback(
1172
+ (draft: Omit<QuestionDraft, "seq">) =>
1173
+ setQuestionDraft((previous) => ({ ...draft, seq: previous?.seq ?? 0 })),
1174
+ [],
1175
+ );
953
1176
  const openWorkspace = useCallback(
954
1177
  (preferredRunID?: string | null) => {
955
1178
  setOpen(true);
@@ -1058,11 +1281,22 @@ function RoutedDiagnoseProvider({
1058
1281
  consentBusyRef.current = true;
1059
1282
  setConsentError(null);
1060
1283
  const t = pendingTarget;
1284
+ const approval = ++consentApprovalRef.current;
1061
1285
  // The server ENFORCES consent at start, so the acknowledgment must land
1062
1286
  // before the run request — awaiting also makes it durable for the CLI.
1063
1287
  recordConsent(consentSurface)
1064
1288
  .then(() => {
1065
1289
  setConsented((prev) => ({ ...prev, [consentSurface]: true }));
1290
+ // Cancelled while the acknowledgment was in flight, or the cluster
1291
+ // changed under it: consent is recorded, but the start never runs.
1292
+ if (approval !== consentApprovalRef.current) return;
1293
+ if (
1294
+ t?.context &&
1295
+ currentContextRef.current &&
1296
+ t.context !== currentContextRef.current
1297
+ ) {
1298
+ return;
1299
+ }
1066
1300
  // Cleared only on success: a failed write keeps the consent card up
1067
1301
  // (needsConsent = !!pendingTarget) so "try again" works in place.
1068
1302
  setPendingTarget(null);
@@ -1084,12 +1318,30 @@ function RoutedDiagnoseProvider({
1084
1318
  });
1085
1319
  }, [consentSurface, pendingTarget]);
1086
1320
  const cancelConsent = useCallback(() => {
1321
+ consentApprovalRef.current++;
1322
+ if (pendingTarget) giveQuestionBack(pendingTarget);
1087
1323
  setPendingTarget(null);
1088
1324
  setConsentError(null);
1089
1325
  setOpen(true);
1090
1326
  if (!activeRunIdRef.current) setView("home");
1091
- }, []);
1327
+ }, [pendingTarget, giveQuestionBack]);
1092
1328
  const dismissError = useCallback(() => setStartFailure(null), []);
1329
+ useEffect(() => {
1330
+ if (!pendingTarget || !currentContext) return;
1331
+ // A start opened before the cluster was known belongs to the first one
1332
+ // known, so a later switch still drops it.
1333
+ if (!pendingTarget.context) {
1334
+ setPendingTarget({ ...pendingTarget, context: currentContext });
1335
+ return;
1336
+ }
1337
+ if (pendingTarget.context !== currentContext) {
1338
+ consentApprovalRef.current++;
1339
+ giveQuestionBack(pendingTarget);
1340
+ setPendingTarget(null);
1341
+ setConsentError(null);
1342
+ if (!activeRunIdRef.current) setView("home");
1343
+ }
1344
+ }, [currentContext, pendingTarget, giveQuestionBack]);
1093
1345
 
1094
1346
  // Reserve a right gutter on the CONTENT area (not the navbar/rail — those stay
1095
1347
  // global and static) so docked content reflows beside the panel. Wide viewports
@@ -1105,6 +1357,7 @@ function RoutedDiagnoseProvider({
1105
1357
  cliOverride,
1106
1358
  agentLabel,
1107
1359
  hosted,
1360
+ questions: selectedAgentInfo?.questions === true,
1108
1361
  agents,
1109
1362
  selectedAgent,
1110
1363
  setSelectedAgent,
@@ -1123,12 +1376,17 @@ function RoutedDiagnoseProvider({
1123
1376
  // pendingTarget is set ONLY when the current agent's consent is missing, and
1124
1377
  // cleared on approve/cancel — so its presence is exactly "consent needed now".
1125
1378
  needsConsent: !!pendingTarget,
1379
+ pendingTarget,
1126
1380
  startError: startFailure?.message ?? null,
1127
1381
  startRefusal: startFailure?.refusal ?? null,
1382
+ startCapacity: startFailure?.capacity ?? null,
1128
1383
  consentError,
1129
1384
  openInvestigation,
1130
1385
  openRun,
1131
1386
  openHome,
1387
+ openQuestion,
1388
+ saveQuestionDraft,
1389
+ questionDraft,
1132
1390
  openWorkspace,
1133
1391
  restoreWorkspace,
1134
1392
  canRestoreWorkspace,
@@ -1161,7 +1419,9 @@ function RoutedDiagnoseProvider({
1161
1419
  panelBounds: PANEL_BOUNDS,
1162
1420
  panelWidthKey: WIDTH_KEY,
1163
1421
  runningKeys,
1422
+ runningRunIds,
1164
1423
  runningCount,
1424
+ lastInvestigations: lastInvestigationsByKey,
1165
1425
  }),
1166
1426
  [
1167
1427
  open,
@@ -1173,7 +1433,9 @@ function RoutedDiagnoseProvider({
1173
1433
  width,
1174
1434
  narrow,
1175
1435
  runningKeys,
1436
+ runningRunIds,
1176
1437
  runningCount,
1438
+ lastInvestigationsByKey,
1177
1439
  setMaximized,
1178
1440
  setWidth,
1179
1441
  ],
@@ -4,6 +4,7 @@ import {
4
4
  INVESTIGATION_HISTORY_MIN_WIDTH,
5
5
  MAXIMIZED_RUN_META_VISIBILITY_CLASS,
6
6
  canRerunInvestigation,
7
+ consentSubject,
7
8
  investigationHistoryIsPersistent,
8
9
  investigationHeaderPresentation,
9
10
  openInvestigationEvidenceResource,
@@ -40,6 +41,27 @@ describe("canRerunInvestigation", () => {
40
41
  );
41
42
  });
42
43
 
44
+ it("re-runs a finished question-only run from its question", () => {
45
+ const questionOnly = {
46
+ ...run("done"),
47
+ kind: "",
48
+ group: "",
49
+ namespace: "",
50
+ name: "",
51
+ question: "checkout is slow",
52
+ };
53
+ expect(canRerunInvestigation("investigation", questionOnly, false)).toBe(
54
+ true,
55
+ );
56
+ expect(
57
+ canRerunInvestigation(
58
+ "investigation",
59
+ { ...questionOnly, question: undefined },
60
+ false,
61
+ ),
62
+ ).toBe(false);
63
+ });
64
+
43
65
  it("stays hidden on the investigations list", () => {
44
66
  // Home is a fresh-entry surface and must never expose a token-spending
45
67
  // re-run action, even if a stale caller hands the header a run.
@@ -375,3 +397,35 @@ describe("canInvestigateFurther", () => {
375
397
  ).toBe(false);
376
398
  });
377
399
  });
400
+
401
+ describe("consentSubject", () => {
402
+ it("names a question run by its question and where it starts", () => {
403
+ expect(
404
+ consentSubject({
405
+ kind: "",
406
+ group: "",
407
+ namespace: "",
408
+ name: "",
409
+ question: "checkout is slow",
410
+ namespaces: [],
411
+ lookBack: "1h",
412
+ }),
413
+ ).toEqual({
414
+ title: "“checkout is slow”",
415
+ detail: "All namespaces · last 1h",
416
+ question: true,
417
+ });
418
+ });
419
+
420
+ it("names a resource run by its resource", () => {
421
+ expect(
422
+ consentSubject({
423
+ kind: "Deployment",
424
+ group: "apps",
425
+ namespace: "shop",
426
+ name: "api",
427
+ }),
428
+ ).toEqual({ title: "Deployment shop/api", detail: undefined });
429
+ expect(consentSubject(null)).toBeUndefined();
430
+ });
431
+ });