@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
@@ -29,15 +29,17 @@ 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";
41
43
  import { knownKindForPluralWithGroup } from "../../utils/navigation";
42
44
 
43
45
  export interface Target {
@@ -54,9 +56,45 @@ export interface Target {
54
56
  * the consent-deferred path replays one object — a parallel "was it fresh?"
55
57
  * state is a thing that can fall out of sync with the target it describes. */
56
58
  fresh?: boolean;
59
+ /** The engineer's question. With an empty kind and name, the run is about
60
+ * the question alone. */
61
+ question?: string;
62
+ namespaces?: string[];
63
+ lookBack?: string;
64
+ /** When the question was first asked, for a run that re-runs or narrows
65
+ * an earlier one; absent means now. */
66
+ askedAt?: string;
67
+ /** Started from the question composer, which hands its draft over to the
68
+ * start: a start that never becomes a run gives the question back. */
69
+ fromComposer?: boolean;
70
+ /** The cluster the start was made in; set when it is opened. */
71
+ context?: string;
57
72
  }
58
73
  export type DiagnoseView = "home" | "investigation";
59
74
 
75
+ // What the question composer opens with when something hands it a start:
76
+ // the resource to pin, the words typed so far. seq makes a second hand-off
77
+ // with the same content still land.
78
+ export interface QuestionDraft {
79
+ seq: number;
80
+ text?: string;
81
+ pin?: { kind: string; group: string; namespace: string; name: string };
82
+ namespaces?: string[];
83
+ lookBack?: string;
84
+ /** A question handed back because its start never became a run: a
85
+ * composer already holding other words keeps them. */
86
+ restore?: boolean;
87
+ /** Open the resource picker with it: choose the resource to ask about. */
88
+ pickResource?: boolean;
89
+ /** When the handed-over question was first asked; kept while its words are. */
90
+ askedAt?: string;
91
+ /** The cluster the pin and namespaces were chosen in. */
92
+ context?: string;
93
+ /** A hand-off that brings no words of its own (Ask about a resource):
94
+ * whatever the engineer already wrote stays. */
95
+ keepWords?: boolean;
96
+ }
97
+
60
98
  // Setup readiness of local AI investigations, derived from the agents API:
61
99
  // - "ready": an agent is installed and the engine is running (available)
62
100
  // - "needs-install": the feature is supported here but no agent CLI is installed
@@ -87,6 +125,7 @@ interface DiagnoseCtx {
87
125
  cliOverride: boolean;
88
126
  agentLabel: string; // label of the selected agent, e.g. "Claude Code"
89
127
  hosted: boolean; // selected agent runs on the host's backend, not this machine
128
+ questions: boolean; // the selected agent's backend opens a run from a question
90
129
  agents: AgentInfo[]; // supported agents detected on PATH (for the picker)
91
130
  selectedAgent: string; // name of the chosen backend ("claude"/"codex")
92
131
  setSelectedAgent: (name: string) => void;
@@ -103,10 +142,15 @@ interface DiagnoseCtx {
103
142
  runsLoadFailed: boolean; // latest runs fetch failed (poll keeps retrying)
104
143
  historyDegraded: boolean; // persistence broke — history won't survive a restart
105
144
  needsConsent: boolean; // a start is pending the one-time consent
145
+ pendingTarget: Target | null; // what that pending start is about
106
146
  startError: string | null;
107
147
  // The host's refusal behind startError, when it sent one, so the surface can
108
148
  // offer the host's action beside the message.
109
149
  startRefusal: InvestigationRefusal | null;
150
+ // Set when the start failed because every investigation slot is taken: the
151
+ // start to retry once one is free, how many run at once, and the cluster
152
+ // the start was refused in.
153
+ startCapacity: StartCapacity | null;
110
154
  // Kept apart from startError: the consent card renders this as "why your
111
155
  // approval was refused", and a run-start failure landing in the same slot
112
156
  // would be read as exactly that — the two paths don't share a lifecycle.
@@ -114,6 +158,12 @@ interface DiagnoseCtx {
114
158
  openInvestigation: (t: Target) => void;
115
159
  openRun: (id: string) => void;
116
160
  openHome: () => void;
161
+ // Opens Home's question composer with a resource pinned or words typed.
162
+ openQuestion: (draft: Omit<QuestionDraft, "seq">) => void;
163
+ // Keeps the composer's unsent content when it unmounts, without handing it
164
+ // back to the composer as a new start.
165
+ saveQuestionDraft: (draft: Omit<QuestionDraft, "seq">) => void;
166
+ questionDraft: QuestionDraft | null;
117
167
  openWorkspace: (runID?: string | null) => void;
118
168
  restoreWorkspace: () => void;
119
169
  canRestoreWorkspace: boolean;
@@ -145,6 +195,10 @@ interface DiagnoseLayoutCtx {
145
195
  panelBounds: { min: number; max: number };
146
196
  panelWidthKey: string;
147
197
  runningKeys: ReadonlySet<string>; // resources with a live investigation (see runTargetKey)
198
+ // The live run behind each running key, so "view it" opens that run rather
199
+ // than starting another: a question someone asked about the resource
200
+ // doesn't stand in for a fresh resource start.
201
+ runningRunIds: ReadonlyMap<string, string>;
148
202
  runningCount: number;
149
203
  }
150
204
 
@@ -232,6 +286,20 @@ export function agentLabelFor(name: string, fallbackLabel?: string): string {
232
286
  return AGENT_LABELS[name] || fallbackLabel || name || "your AI agent";
233
287
  }
234
288
 
289
+ export interface StartCapacity {
290
+ target: Target;
291
+ limit: number;
292
+ context?: string;
293
+ }
294
+
295
+ function startCapacity(
296
+ error: unknown,
297
+ target: Target,
298
+ ): StartCapacity | undefined {
299
+ const capacity = investigationCapacity(error);
300
+ return capacity ? { target, ...capacity } : undefined;
301
+ }
302
+
235
303
  // openDiagnoseSettings opens the Settings dialog (App.tsx listens for this DOM
236
304
  // event) — the canonical home for AI investigation config.
237
305
  export function openDiagnoseSettings() {
@@ -472,9 +540,52 @@ function RoutedDiagnoseProvider({
472
540
  const [runsLoadFailed, setRunsLoadFailed] = useState(false);
473
541
  const [historyDegraded, setHistoryDegraded] = useState(false);
474
542
  const [pendingTarget, setPendingTarget] = useState<Target | null>(null);
543
+ // The question composer's content outside the composer, so a hand-off can
544
+ // fill it and a start that never became a run (consent cancelled, a refused
545
+ // start) hands the engineer's words back instead of losing them.
546
+ const [questionDraft, setQuestionDraft] = useState<QuestionDraft | null>(
547
+ null,
548
+ );
549
+ const consentApprovalRef = useRef(0);
550
+ // The cluster in use now. A start waiting on consent names things in the
551
+ // cluster it was made in; if the cluster changes first, it is dropped
552
+ // rather than run against same-named things in the new one.
553
+ const { data: contexts } = useContexts();
554
+ const currentContext = contexts?.find((context) => context.isCurrent)?.name;
555
+ const currentContextRef = useRef(currentContext);
556
+ currentContextRef.current = currentContext;
557
+ // A question that never became a run goes back to the composer, unless the
558
+ // engineer has written something else there since.
559
+ const giveQuestionBack = useCallback((t: Target) => {
560
+ if (!t.fromComposer || !t.question) return;
561
+ setQuestionDraft((previous) =>
562
+ previous?.text?.trim()
563
+ ? previous
564
+ : {
565
+ seq: (previous?.seq ?? 0) + 1,
566
+ text: t.question,
567
+ pin: t.name
568
+ ? {
569
+ kind: t.kind,
570
+ group: t.group,
571
+ namespace: t.namespace,
572
+ name: t.name,
573
+ }
574
+ : undefined,
575
+ // An empty list is an explicit "all namespaces", not "follow the
576
+ // header": hand it back as it was.
577
+ namespaces: t.namespaces,
578
+ lookBack: t.lookBack,
579
+ askedAt: t.askedAt,
580
+ context: t.context,
581
+ restore: true,
582
+ },
583
+ );
584
+ }, []);
475
585
  const [startFailure, setStartFailure] = useState<{
476
586
  message: string;
477
587
  refusal: InvestigationRefusal | null;
588
+ capacity?: StartCapacity;
478
589
  } | null>(null);
479
590
  const [consentError, setConsentError] = useState<string | null>(null);
480
591
  const [width, setWidth] = useState<number>(() => {
@@ -723,16 +834,32 @@ function RoutedDiagnoseProvider({
723
834
  // A content-stable signature of the resources with a live investigation,
724
835
  // so per-resource Investigate buttons only re-render when their live targets
725
836
  // change.
837
+ // A plain resource run sorts after a question about the same resource, so
838
+ // it is the one a key maps to when both are live.
726
839
  const runningSig = runningRuns
727
- .map((r) => runTargetKey(r.kind, r.namespace, r.name, r.group))
840
+ .filter((r) => !isQuestionOnly(r))
841
+ .map(
842
+ (r) =>
843
+ `${runTargetKey(r.kind, r.namespace, r.name, r.group)}\t${r.question ? 0 : 1}\t${r.id}`,
844
+ )
728
845
  .sort()
729
- // resourceKey itself is pipe-delimited; newlines cannot occur in a
730
- // Kubernetes group, Kind, namespace, or name.
846
+ // resourceKey itself is pipe-delimited; newlines and tabs cannot occur in
847
+ // a Kubernetes group, Kind, namespace, or name.
731
848
  .join("\n");
732
- const runningKeys = useMemo(
733
- () => new Set(runningSig ? runningSig.split("\n") : []),
849
+ const runningRunIds = useMemo(
850
+ () =>
851
+ new Map(
852
+ (runningSig ? runningSig.split("\n") : []).map((line) => {
853
+ const [key, , id] = line.split("\t");
854
+ return [key, id] as const;
855
+ }),
856
+ ),
734
857
  [runningSig],
735
858
  );
859
+ const runningKeys = useMemo(
860
+ () => new Set(runningRunIds.keys()),
861
+ [runningRunIds],
862
+ );
736
863
  const runningCount = runningRuns.length;
737
864
  const hasRunning = runningCount > 0;
738
865
 
@@ -780,18 +907,24 @@ function RoutedDiagnoseProvider({
780
907
  // fetched; refresh it so the picker shows what's installed now.
781
908
  void recheckAgents();
782
909
  if (seq !== startSeqRef.current) return;
910
+ giveQuestionBack(t);
783
911
  setStartFailure({
784
912
  message:
785
913
  e instanceof DiagnoseError
786
914
  ? e.message
787
915
  : "Couldn't start the investigation.",
788
916
  refusal: investigationRefusal(e),
917
+ capacity: startCapacity(e, t),
789
918
  });
790
919
  });
791
920
  };
792
921
 
793
922
  const openInvestigation = useCallback(
794
- (t: Target) => {
923
+ (opened: Target) => {
924
+ const t = {
925
+ ...opened,
926
+ context: opened.context ?? currentContextRef.current,
927
+ };
795
928
  setStartFailure(null);
796
929
  setConsentError(null);
797
930
  setOpen(true);
@@ -802,6 +935,7 @@ function RoutedDiagnoseProvider({
802
935
  "Radar can’t run this agent with a verified execution profile.",
803
936
  refusal: null,
804
937
  });
938
+ giveQuestionBack(t);
805
939
  setView("investigation");
806
940
  return;
807
941
  }
@@ -813,11 +947,14 @@ function RoutedDiagnoseProvider({
813
947
  setView("investigation");
814
948
  startRunRef.current(t);
815
949
  },
816
- [consentSurface, hosted],
950
+ [consentSurface, hosted, giveQuestionBack],
817
951
  );
818
952
  const openRun = useCallback(
819
953
  (id: string) => {
820
954
  unavailableRunIDsRef.current.delete(id);
955
+ // A start still in flight no longer owns the pane: its refusal must not
956
+ // replace the run the user just chose.
957
+ startSeqRef.current++;
821
958
  setStartFailure(null);
822
959
  setActiveRunId(id);
823
960
  setView("investigation");
@@ -950,6 +1087,28 @@ function RoutedDiagnoseProvider({
950
1087
  setOpen(true);
951
1088
  writeFocusedRunID(null, false);
952
1089
  }, [writeFocusedRunID]);
1090
+ const openQuestion = useCallback(
1091
+ (draft: Omit<QuestionDraft, "seq">) => {
1092
+ setQuestionDraft((previous) =>
1093
+ draft.text === undefined
1094
+ ? {
1095
+ ...draft,
1096
+ text: previous?.text,
1097
+ askedAt: previous?.askedAt,
1098
+ keepWords: true,
1099
+ seq: (previous?.seq ?? 0) + 1,
1100
+ }
1101
+ : { ...draft, seq: (previous?.seq ?? 0) + 1 },
1102
+ );
1103
+ openHome();
1104
+ },
1105
+ [openHome],
1106
+ );
1107
+ const saveQuestionDraft = useCallback(
1108
+ (draft: Omit<QuestionDraft, "seq">) =>
1109
+ setQuestionDraft((previous) => ({ ...draft, seq: previous?.seq ?? 0 })),
1110
+ [],
1111
+ );
953
1112
  const openWorkspace = useCallback(
954
1113
  (preferredRunID?: string | null) => {
955
1114
  setOpen(true);
@@ -1058,11 +1217,22 @@ function RoutedDiagnoseProvider({
1058
1217
  consentBusyRef.current = true;
1059
1218
  setConsentError(null);
1060
1219
  const t = pendingTarget;
1220
+ const approval = ++consentApprovalRef.current;
1061
1221
  // The server ENFORCES consent at start, so the acknowledgment must land
1062
1222
  // before the run request — awaiting also makes it durable for the CLI.
1063
1223
  recordConsent(consentSurface)
1064
1224
  .then(() => {
1065
1225
  setConsented((prev) => ({ ...prev, [consentSurface]: true }));
1226
+ // Cancelled while the acknowledgment was in flight, or the cluster
1227
+ // changed under it: consent is recorded, but the start never runs.
1228
+ if (approval !== consentApprovalRef.current) return;
1229
+ if (
1230
+ t?.context &&
1231
+ currentContextRef.current &&
1232
+ t.context !== currentContextRef.current
1233
+ ) {
1234
+ return;
1235
+ }
1066
1236
  // Cleared only on success: a failed write keeps the consent card up
1067
1237
  // (needsConsent = !!pendingTarget) so "try again" works in place.
1068
1238
  setPendingTarget(null);
@@ -1084,12 +1254,30 @@ function RoutedDiagnoseProvider({
1084
1254
  });
1085
1255
  }, [consentSurface, pendingTarget]);
1086
1256
  const cancelConsent = useCallback(() => {
1257
+ consentApprovalRef.current++;
1258
+ if (pendingTarget) giveQuestionBack(pendingTarget);
1087
1259
  setPendingTarget(null);
1088
1260
  setConsentError(null);
1089
1261
  setOpen(true);
1090
1262
  if (!activeRunIdRef.current) setView("home");
1091
- }, []);
1263
+ }, [pendingTarget, giveQuestionBack]);
1092
1264
  const dismissError = useCallback(() => setStartFailure(null), []);
1265
+ useEffect(() => {
1266
+ if (!pendingTarget || !currentContext) return;
1267
+ // A start opened before the cluster was known belongs to the first one
1268
+ // known, so a later switch still drops it.
1269
+ if (!pendingTarget.context) {
1270
+ setPendingTarget({ ...pendingTarget, context: currentContext });
1271
+ return;
1272
+ }
1273
+ if (pendingTarget.context !== currentContext) {
1274
+ consentApprovalRef.current++;
1275
+ giveQuestionBack(pendingTarget);
1276
+ setPendingTarget(null);
1277
+ setConsentError(null);
1278
+ if (!activeRunIdRef.current) setView("home");
1279
+ }
1280
+ }, [currentContext, pendingTarget, giveQuestionBack]);
1093
1281
 
1094
1282
  // Reserve a right gutter on the CONTENT area (not the navbar/rail — those stay
1095
1283
  // global and static) so docked content reflows beside the panel. Wide viewports
@@ -1105,6 +1293,7 @@ function RoutedDiagnoseProvider({
1105
1293
  cliOverride,
1106
1294
  agentLabel,
1107
1295
  hosted,
1296
+ questions: selectedAgentInfo?.questions === true,
1108
1297
  agents,
1109
1298
  selectedAgent,
1110
1299
  setSelectedAgent,
@@ -1123,12 +1312,17 @@ function RoutedDiagnoseProvider({
1123
1312
  // pendingTarget is set ONLY when the current agent's consent is missing, and
1124
1313
  // cleared on approve/cancel — so its presence is exactly "consent needed now".
1125
1314
  needsConsent: !!pendingTarget,
1315
+ pendingTarget,
1126
1316
  startError: startFailure?.message ?? null,
1127
1317
  startRefusal: startFailure?.refusal ?? null,
1318
+ startCapacity: startFailure?.capacity ?? null,
1128
1319
  consentError,
1129
1320
  openInvestigation,
1130
1321
  openRun,
1131
1322
  openHome,
1323
+ openQuestion,
1324
+ saveQuestionDraft,
1325
+ questionDraft,
1132
1326
  openWorkspace,
1133
1327
  restoreWorkspace,
1134
1328
  canRestoreWorkspace,
@@ -1161,6 +1355,7 @@ function RoutedDiagnoseProvider({
1161
1355
  panelBounds: PANEL_BOUNDS,
1162
1356
  panelWidthKey: WIDTH_KEY,
1163
1357
  runningKeys,
1358
+ runningRunIds,
1164
1359
  runningCount,
1165
1360
  }),
1166
1361
  [
@@ -1173,6 +1368,7 @@ function RoutedDiagnoseProvider({
1173
1368
  width,
1174
1369
  narrow,
1175
1370
  runningKeys,
1371
+ runningRunIds,
1176
1372
  runningCount,
1177
1373
  setMaximized,
1178
1374
  setWidth,
@@ -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
+ });