@skyhook-io/radar-app 1.18.2 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/App.tsx +0 -1
- package/src/api/diagnose.test.ts +33 -2
- package/src/api/diagnose.ts +93 -3
- package/src/api/radarFeatures.ts +1 -0
- package/src/components/diagnose/AIMarkdown.tsx +1 -1
- package/src/components/diagnose/ActivityTurn.tsx +34 -14
- package/src/components/diagnose/AgentControls.tsx +53 -6
- package/src/components/diagnose/AgentSetupNotice.tsx +1 -1
- package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
- package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
- package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
- package/src/components/diagnose/AnalysisStory.tsx +17 -4
- package/src/components/diagnose/AssessmentCard.tsx +39 -8
- package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
- package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
- package/src/components/diagnose/DiagnoseContext.tsx +205 -9
- package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
- package/src/components/diagnose/DiagnoseSurface.tsx +93 -21
- package/src/components/diagnose/EvidenceCard.tsx +67 -14
- package/src/components/diagnose/Home.test.tsx +182 -5
- package/src/components/diagnose/Home.tsx +168 -36
- package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
- package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
- package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
- package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
- package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
- package/src/components/diagnose/InvestigationEvidenceSections.tsx +5 -1
- package/src/components/diagnose/InvestigationView.tsx +156 -29
- package/src/components/diagnose/LocalDiagnoseAction.tsx +23 -16
- package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
- package/src/components/diagnose/QuestionComposer.tsx +487 -0
- package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
- package/src/components/diagnose/QuestionFocus.tsx +123 -0
- package/src/components/diagnose/ResourcePicker.tsx +206 -0
- package/src/components/diagnose/StoryExcerpt.tsx +12 -3
- package/src/components/diagnose/assessmentCopy.ts +5 -0
- package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
- package/src/components/diagnose/investigationCase.ts +33 -1
- package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
- package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +8 -0
- package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
- package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
- package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
- package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
- package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
- package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
- package/src/components/diagnose/investigationEvidence/index.ts +1 -1
- package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
- package/src/components/diagnose/investigationEvidence/types.ts +2 -0
- package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
- package/src/components/diagnose/investigationFocus.test.ts +271 -0
- package/src/components/diagnose/investigationFocus.ts +132 -0
- package/src/components/diagnose/parts.test.tsx +20 -0
- package/src/components/diagnose/questionSuggestions.test.ts +111 -0
- package/src/components/diagnose/questionSuggestions.ts +150 -0
- package/src/components/diagnose/storyParts.test.tsx +13 -0
- package/src/components/diagnose/target.test.ts +143 -2
- package/src/components/diagnose/target.ts +109 -7
- package/src/components/diagnose/testdata/story-runs.json +474 -0
- package/src/components/diagnose/verdictText.test.tsx +87 -0
- package/src/components/diagnose/verdictText.ts +68 -0
- package/src/components/home/ClusterHealthCard.tsx +13 -39
- package/src/components/home/HomeAgentBlock.test.tsx +113 -0
- package/src/components/home/HomeAgentBlock.tsx +94 -0
- package/src/components/home/HomeView.tsx +5 -6
- package/src/components/home/RadarVersionLine.test.tsx +0 -14
- package/src/components/home/RadarVersionLine.tsx +3 -28
- package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
- package/src/components/ui/Omnibar.tsx +47 -3
- package/src/components/ui/RadarOmnibar.test.tsx +1 -0
- package/src/components/ui/RadarOmnibar.tsx +11 -0
- package/src/components/whats-new/WhatsNewDialog.test.tsx +3 -3
- package/src/components/whats-new/releaseNotes.ts +60 -1
- package/src/hooks/useAgentSignin.test.tsx +190 -0
- package/src/hooks/useAgentSignin.ts +160 -0
- package/src/hooks/useApproveAfterSignin.test.tsx +108 -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
|
-
.
|
|
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
|
|
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
|
|
733
|
-
() =>
|
|
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
|
-
(
|
|
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
|
+
});
|
|
@@ -36,9 +36,11 @@ import {
|
|
|
36
36
|
agentLabelFor,
|
|
37
37
|
openDiagnoseSettings,
|
|
38
38
|
type DiagnoseView,
|
|
39
|
+
type Target,
|
|
39
40
|
} from "./DiagnoseContext";
|
|
40
41
|
import { useDiagnoseCustomization } from "../../context/DiagnoseCustomization";
|
|
41
42
|
import { InvestigationRefusalAction } from "./InvestigationRefusalAction";
|
|
43
|
+
import { InvestigationCapacityRecovery } from "./InvestigationCapacityNotice";
|
|
42
44
|
import { useNavCustomization } from "../../context/NavCustomization";
|
|
43
45
|
import { InvestigationView } from "./InvestigationView";
|
|
44
46
|
import type { InvestigationTimelineScope } from "./InvestigationEvidencePane";
|
|
@@ -49,13 +51,25 @@ import {
|
|
|
49
51
|
statusWord,
|
|
50
52
|
} from "./Home";
|
|
51
53
|
import { AgentSetupNotice } from "./AgentSetupNotice";
|
|
54
|
+
import { AgentSigninNotice } from "./AgentSigninNotice";
|
|
55
|
+
import {
|
|
56
|
+
useAgentSignin,
|
|
57
|
+
useApproveAfterSignin,
|
|
58
|
+
} from "../../hooks/useAgentSignin";
|
|
52
59
|
import { ConsentCard } from "./parts";
|
|
60
|
+
import type { ConsentSubject } from "./AgentControls";
|
|
53
61
|
import { buildLaunchCommand, launchAgentLabel, openInTerminal } from "./launch";
|
|
54
62
|
import { type RunSummary, type ExecutionProfile } from "../../api/diagnose";
|
|
55
63
|
import { mcpEndpointUrl } from "../../api/config";
|
|
56
64
|
import { useCapabilitiesContext } from "../../contexts/CapabilitiesContext";
|
|
57
65
|
import { useContexts } from "../../api/client";
|
|
58
|
-
import {
|
|
66
|
+
import {
|
|
67
|
+
formatInvestigationTarget,
|
|
68
|
+
formatInvestigationTitle,
|
|
69
|
+
formatQuestionScope,
|
|
70
|
+
isQuestionOnly,
|
|
71
|
+
rerunOpening,
|
|
72
|
+
} from "./target";
|
|
59
73
|
import type { DiagnosisResourceRef } from "./diagnoseEvidenceTypes";
|
|
60
74
|
|
|
61
75
|
function capWord(s: string): string {
|
|
@@ -194,7 +208,7 @@ function InvestigationMenu({ run }: { run: RunSummary }) {
|
|
|
194
208
|
// Every clause is a failure this button actually had:
|
|
195
209
|
//
|
|
196
210
|
// view Home is the fresh-entry surface, never a re-run action.
|
|
197
|
-
// run nothing to take a resource from.
|
|
211
|
+
// run nothing to take a resource or question from.
|
|
198
212
|
// running/stopping human starts reuse the live run. Automatic investigations
|
|
199
213
|
// are immutable, so they retain a separate fresh human start.
|
|
200
214
|
// stale the original session is closed after a cluster switch;
|
|
@@ -209,8 +223,7 @@ export function canRerunInvestigation(
|
|
|
209
223
|
return (
|
|
210
224
|
view === "investigation" &&
|
|
211
225
|
!!run &&
|
|
212
|
-
!!run.kind &&
|
|
213
|
-
!!run.name &&
|
|
226
|
+
((!!run.kind && !!run.name) || isQuestionOnly(run)) &&
|
|
214
227
|
((run.status !== "running" && run.status !== "stopping") ||
|
|
215
228
|
run.trigger === "background") &&
|
|
216
229
|
run.status !== "stale" &&
|
|
@@ -232,6 +245,25 @@ export const MAXIMIZED_RUN_META_VISIBILITY_CLASS =
|
|
|
232
245
|
export const DIAGNOSE_SURFACE_FRAME_CLASS =
|
|
233
246
|
"@container/diagnose-surface absolute z-40 flex min-h-0 flex-col overflow-hidden border-l border-theme-border bg-theme-surface shadow-drawer";
|
|
234
247
|
|
|
248
|
+
// The consent card names what it is about to investigate, so approving it is
|
|
249
|
+
// approving that run.
|
|
250
|
+
export function consentSubject(
|
|
251
|
+
target: Target | null,
|
|
252
|
+
): ConsentSubject | undefined {
|
|
253
|
+
if (!target) return undefined;
|
|
254
|
+
if (isQuestionOnly(target)) {
|
|
255
|
+
return {
|
|
256
|
+
title: `“${formatInvestigationTitle(target)}”`,
|
|
257
|
+
detail: formatQuestionScope(target),
|
|
258
|
+
question: true,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
title: formatInvestigationTarget(target),
|
|
263
|
+
detail: target.question ? `Asked: ${target.question}` : undefined,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
235
267
|
export function unavailableInvestigationMessage(embedded: boolean): string {
|
|
236
268
|
return embedded
|
|
237
269
|
? "This investigation is unavailable. It may be private, your access may have changed, or its history may have been cleared. Check your account and organization, or ask the creator for access."
|
|
@@ -381,6 +413,28 @@ export function DiagnoseSurface({
|
|
|
381
413
|
onBrowseIssues?: () => void;
|
|
382
414
|
}) {
|
|
383
415
|
const d = useDiagnose();
|
|
416
|
+
// A hosted agent runs on the host's backend, where a local CLI's sign-in
|
|
417
|
+
// says nothing.
|
|
418
|
+
const signin = useAgentSignin(
|
|
419
|
+
d.selectedAgent,
|
|
420
|
+
d.profile,
|
|
421
|
+
d.needsConsent && !d.hosted,
|
|
422
|
+
);
|
|
423
|
+
const consentActions = useApproveAfterSignin({
|
|
424
|
+
approve: d.approveConsent,
|
|
425
|
+
cancel: d.cancelConsent,
|
|
426
|
+
signin,
|
|
427
|
+
attemptKey: `${d.selectedAgent}\u0000${d.profile}\u0000${d.needsConsent}`,
|
|
428
|
+
});
|
|
429
|
+
const signinNotice =
|
|
430
|
+
signin.status?.state === "signed-out" && signin.status.signinCmd ? (
|
|
431
|
+
<AgentSigninNotice
|
|
432
|
+
agentName={d.agentLabel}
|
|
433
|
+
signinCmd={signin.status.signinCmd}
|
|
434
|
+
rechecking={signin.rechecking}
|
|
435
|
+
onRecheck={signin.recheck}
|
|
436
|
+
/>
|
|
437
|
+
) : null;
|
|
384
438
|
const { data: contexts } = useContexts();
|
|
385
439
|
const currentContext = contexts?.find((context) => context.isCurrent)?.name;
|
|
386
440
|
const [historyCollapsed, setHistoryCollapsed] = useState(false);
|
|
@@ -514,7 +568,8 @@ export function DiagnoseSurface({
|
|
|
514
568
|
const activeRun = d.runs.find((r) => r.id === d.activeRunId) ?? null;
|
|
515
569
|
// Consent replaces the detail pane even if goHome retained an older run id.
|
|
516
570
|
// Header identity and actions must describe what is actually visible.
|
|
517
|
-
const visibleRunDetail =
|
|
571
|
+
const visibleRunDetail =
|
|
572
|
+
d.needsConsent || d.startCapacity ? null : activeRun;
|
|
518
573
|
// A focused run shows the agent it actually ran with; Home reflects the current pick.
|
|
519
574
|
const activeAgentLabel = visibleRunDetail?.agent
|
|
520
575
|
? agentLabelFor(visibleRunDetail.agent)
|
|
@@ -530,7 +585,7 @@ export function DiagnoseSurface({
|
|
|
530
585
|
visibleRunDetail ?? defaultHeaderConfig,
|
|
531
586
|
);
|
|
532
587
|
const focusedTitle = visibleRunDetail
|
|
533
|
-
?
|
|
588
|
+
? formatInvestigationTitle(visibleRunDetail)
|
|
534
589
|
: "AI investigations";
|
|
535
590
|
const headerPresentation = investigationHeaderPresentation({
|
|
536
591
|
view: d.view,
|
|
@@ -567,13 +622,20 @@ export function DiagnoseSurface({
|
|
|
567
622
|
agent={d.selectedAgent}
|
|
568
623
|
profile={d.profile}
|
|
569
624
|
copy={consentCopy}
|
|
625
|
+
subject={consentSubject(d.pendingTarget)}
|
|
570
626
|
onOpenSettings={openSettings ?? undefined}
|
|
571
627
|
error={d.consentError}
|
|
572
|
-
|
|
573
|
-
|
|
628
|
+
notice={signinNotice}
|
|
629
|
+
approveBusy={consentActions.waiting}
|
|
630
|
+
onApprove={consentActions.approve}
|
|
631
|
+
onCancel={consentActions.cancel}
|
|
574
632
|
/>
|
|
575
633
|
</div>
|
|
576
634
|
</div>
|
|
635
|
+
) : d.startCapacity ? (
|
|
636
|
+
// Before the focused run: the start the user just asked for is what this
|
|
637
|
+
// pane is about, and a focused run's view would bury the way out.
|
|
638
|
+
<InvestigationCapacityRecovery capacity={d.startCapacity} />
|
|
577
639
|
) : activeRun ? (
|
|
578
640
|
<InvestigationView
|
|
579
641
|
key={activeRun.id}
|
|
@@ -613,6 +675,14 @@ export function DiagnoseSurface({
|
|
|
613
675
|
<p className="text-sm text-theme-text-secondary">{d.startError}</p>
|
|
614
676
|
<div className="flex flex-wrap items-center justify-center gap-2">
|
|
615
677
|
<InvestigationRefusalAction refusal={d.startRefusal} />
|
|
678
|
+
{d.questionDraft?.text && (
|
|
679
|
+
<button
|
|
680
|
+
onClick={d.openHome}
|
|
681
|
+
className="rounded-lg border border-theme-border px-3 py-1.5 text-sm text-theme-text-secondary hover:bg-theme-hover"
|
|
682
|
+
>
|
|
683
|
+
Back to your question
|
|
684
|
+
</button>
|
|
685
|
+
)}
|
|
616
686
|
<button
|
|
617
687
|
onClick={d.dismissError}
|
|
618
688
|
className="rounded-lg border border-theme-border px-3 py-1.5 text-sm text-theme-text-secondary hover:bg-theme-hover"
|
|
@@ -643,10 +713,13 @@ export function DiagnoseSurface({
|
|
|
643
713
|
agent={d.selectedAgent}
|
|
644
714
|
profile={d.profile}
|
|
645
715
|
copy={consentCopy}
|
|
716
|
+
subject={consentSubject(d.pendingTarget)}
|
|
646
717
|
onOpenSettings={openSettings ?? undefined}
|
|
647
718
|
error={d.consentError}
|
|
648
|
-
|
|
649
|
-
|
|
719
|
+
notice={signinNotice}
|
|
720
|
+
approveBusy={consentActions.waiting}
|
|
721
|
+
onApprove={consentActions.approve}
|
|
722
|
+
onCancel={consentActions.cancel}
|
|
650
723
|
/>
|
|
651
724
|
</div>
|
|
652
725
|
) : setupPending ? (
|
|
@@ -662,8 +735,11 @@ export function DiagnoseSurface({
|
|
|
662
735
|
) : (
|
|
663
736
|
<InvestigationHome
|
|
664
737
|
agentLabel={d.agentLabel}
|
|
738
|
+
questions={d.questions}
|
|
665
739
|
onBrowseIssues={
|
|
666
|
-
d.runsLoaded && d.runs.length === 0
|
|
740
|
+
d.questions || (d.runsLoaded && d.runs.length === 0)
|
|
741
|
+
? onBrowseIssues
|
|
742
|
+
: undefined
|
|
667
743
|
}
|
|
668
744
|
/>
|
|
669
745
|
);
|
|
@@ -770,22 +846,14 @@ export function DiagnoseSurface({
|
|
|
770
846
|
</div>
|
|
771
847
|
<div className="flex shrink-0 items-center gap-1">
|
|
772
848
|
{activeRun &&
|
|
849
|
+
visibleRunDetail &&
|
|
773
850
|
canRerunInvestigation(d.view, activeRun, d.needsConsent) && (
|
|
774
851
|
<Tooltip
|
|
775
852
|
content="Re-run this investigation from scratch"
|
|
776
853
|
position="bottom"
|
|
777
854
|
>
|
|
778
855
|
<button
|
|
779
|
-
onClick={() =>
|
|
780
|
-
d.openInvestigation({
|
|
781
|
-
kind: activeRun.kind,
|
|
782
|
-
group: activeRun.group,
|
|
783
|
-
namespace: activeRun.namespace,
|
|
784
|
-
name: activeRun.name,
|
|
785
|
-
issueId: activeRun.issueId,
|
|
786
|
-
fresh: true,
|
|
787
|
-
})
|
|
788
|
-
}
|
|
856
|
+
onClick={() => d.openInvestigation(rerunOpening(activeRun))}
|
|
789
857
|
className="rounded-md p-1 text-theme-text-tertiary hover:bg-theme-hover hover:text-theme-text-primary"
|
|
790
858
|
aria-label="Re-run this investigation from scratch"
|
|
791
859
|
>
|
|
@@ -874,6 +942,10 @@ export function DiagnoseSurface({
|
|
|
874
942
|
if (historyOverlay) dismissHistory();
|
|
875
943
|
}}
|
|
876
944
|
historyDegraded={d.historyDegraded}
|
|
945
|
+
loaded={d.runsLoaded}
|
|
946
|
+
loadFailed={d.runsLoadFailed}
|
|
947
|
+
onRetry={d.refreshRuns}
|
|
948
|
+
questions={d.questions}
|
|
877
949
|
/>
|
|
878
950
|
</aside>
|
|
879
951
|
)}
|