@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.
Files changed (78) hide show
  1. package/package.json +4 -4
  2. package/src/App.tsx +0 -1
  3. package/src/api/diagnose.test.ts +33 -2
  4. package/src/api/diagnose.ts +93 -3
  5. package/src/api/radarFeatures.ts +1 -0
  6. package/src/components/diagnose/AIMarkdown.tsx +1 -1
  7. package/src/components/diagnose/ActivityTurn.tsx +34 -14
  8. package/src/components/diagnose/AgentControls.tsx +53 -6
  9. package/src/components/diagnose/AgentSetupNotice.tsx +1 -1
  10. package/src/components/diagnose/AgentSigninNotice.test.tsx +98 -0
  11. package/src/components/diagnose/AgentSigninNotice.tsx +61 -0
  12. package/src/components/diagnose/AnalysisStory.test.tsx +22 -0
  13. package/src/components/diagnose/AnalysisStory.tsx +17 -4
  14. package/src/components/diagnose/AssessmentCard.tsx +39 -8
  15. package/src/components/diagnose/DiagnoseContext.capacity.test.tsx +113 -0
  16. package/src/components/diagnose/DiagnoseContext.question.test.tsx +245 -0
  17. package/src/components/diagnose/DiagnoseContext.tsx +205 -9
  18. package/src/components/diagnose/DiagnoseSurface.test.tsx +54 -0
  19. package/src/components/diagnose/DiagnoseSurface.tsx +93 -21
  20. package/src/components/diagnose/EvidenceCard.tsx +67 -14
  21. package/src/components/diagnose/Home.test.tsx +182 -5
  22. package/src/components/diagnose/Home.tsx +168 -36
  23. package/src/components/diagnose/InvestigationCapacityNotice.test.tsx +246 -0
  24. package/src/components/diagnose/InvestigationCapacityNotice.tsx +241 -0
  25. package/src/components/diagnose/InvestigationEvidencePane.story.test.tsx +97 -6
  26. package/src/components/diagnose/InvestigationEvidencePane.test.tsx +57 -0
  27. package/src/components/diagnose/InvestigationEvidencePane.tsx +59 -11
  28. package/src/components/diagnose/InvestigationEvidenceSections.tsx +5 -1
  29. package/src/components/diagnose/InvestigationView.tsx +156 -29
  30. package/src/components/diagnose/LocalDiagnoseAction.tsx +23 -16
  31. package/src/components/diagnose/QuestionComposer.test.tsx +553 -0
  32. package/src/components/diagnose/QuestionComposer.tsx +487 -0
  33. package/src/components/diagnose/QuestionFocus.test.tsx +38 -0
  34. package/src/components/diagnose/QuestionFocus.tsx +123 -0
  35. package/src/components/diagnose/ResourcePicker.tsx +206 -0
  36. package/src/components/diagnose/StoryExcerpt.tsx +12 -3
  37. package/src/components/diagnose/assessmentCopy.ts +5 -0
  38. package/src/components/diagnose/investigationCase.runs.test.tsx +328 -0
  39. package/src/components/diagnose/investigationCase.ts +33 -1
  40. package/src/components/diagnose/investigationEvidence/adapters/coverage.test.tsx +46 -0
  41. package/src/components/diagnose/investigationEvidence/adapters/diagnose.ts +8 -0
  42. package/src/components/diagnose/investigationEvidence/adapters/posture.ts +29 -1
  43. package/src/components/diagnose/investigationEvidence/adapters/prometheus.test.ts +40 -0
  44. package/src/components/diagnose/investigationEvidence/adapters/prometheus.ts +27 -1
  45. package/src/components/diagnose/investigationEvidence/bodies/metrics.test.tsx +111 -0
  46. package/src/components/diagnose/investigationEvidence/bodies/metrics.tsx +67 -16
  47. package/src/components/diagnose/investigationEvidence/excerpt.test.ts +18 -5
  48. package/src/components/diagnose/investigationEvidence/excerpt.ts +22 -11
  49. package/src/components/diagnose/investigationEvidence/index.ts +1 -1
  50. package/src/components/diagnose/investigationEvidence/navigation.tsx +2 -0
  51. package/src/components/diagnose/investigationEvidence/types.ts +2 -0
  52. package/src/components/diagnose/investigationEvidencePartition.ts +6 -1
  53. package/src/components/diagnose/investigationFocus.test.ts +271 -0
  54. package/src/components/diagnose/investigationFocus.ts +132 -0
  55. package/src/components/diagnose/parts.test.tsx +20 -0
  56. package/src/components/diagnose/questionSuggestions.test.ts +111 -0
  57. package/src/components/diagnose/questionSuggestions.ts +150 -0
  58. package/src/components/diagnose/storyParts.test.tsx +13 -0
  59. package/src/components/diagnose/target.test.ts +143 -2
  60. package/src/components/diagnose/target.ts +109 -7
  61. package/src/components/diagnose/testdata/story-runs.json +474 -0
  62. package/src/components/diagnose/verdictText.test.tsx +87 -0
  63. package/src/components/diagnose/verdictText.ts +68 -0
  64. package/src/components/home/ClusterHealthCard.tsx +13 -39
  65. package/src/components/home/HomeAgentBlock.test.tsx +113 -0
  66. package/src/components/home/HomeAgentBlock.tsx +94 -0
  67. package/src/components/home/HomeView.tsx +5 -6
  68. package/src/components/home/RadarVersionLine.test.tsx +0 -14
  69. package/src/components/home/RadarVersionLine.tsx +3 -28
  70. package/src/components/ui/Omnibar.investigate.test.tsx +105 -0
  71. package/src/components/ui/Omnibar.tsx +47 -3
  72. package/src/components/ui/RadarOmnibar.test.tsx +1 -0
  73. package/src/components/ui/RadarOmnibar.tsx +11 -0
  74. package/src/components/whats-new/WhatsNewDialog.test.tsx +3 -3
  75. package/src/components/whats-new/releaseNotes.ts +60 -1
  76. package/src/hooks/useAgentSignin.test.tsx +190 -0
  77. package/src/hooks/useAgentSignin.ts +160 -0
  78. package/src/hooks/useApproveAfterSignin.test.tsx +108 -0
@@ -0,0 +1,160 @@
1
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
2
+ import { useQuery, useQueryClient } from '@tanstack/react-query'
3
+ import { useRadarFeature } from '../api/client'
4
+ import { getApiBase } from '../api/config'
5
+ import { fetchAgentSignin, type AgentSigninStatus, type ExecutionProfile } from '../api/diagnose'
6
+
7
+ export interface AgentSigninCheck {
8
+ /** The agent's answer; undefined while checking, on failure, or when not checked. */
9
+ status?: AgentSigninStatus
10
+ /** A check is running and has not answered yet. */
11
+ pending: boolean
12
+ rechecking: boolean
13
+ recheck: () => void
14
+ /** Resolves with the answer once the running check settles (undefined on failure or when not checked). */
15
+ settle: () => Promise<AgentSigninStatus | undefined>
16
+ }
17
+
18
+ // The server caches its answer for a minute; matching it keeps a reopened
19
+ // consent card from asking again.
20
+ const SIGNIN_STALE_MS = 60_000
21
+ // Longest an early Approve waits for the answer: the server's 2s command
22
+ // timeout plus the round trip.
23
+ const SETTLE_MAX_MS = 2_500
24
+
25
+ /**
26
+ * Asks whether a local agent CLI is signed in for runs with this profile, for
27
+ * the consent step. Never blocks: the card renders at once and the answer
28
+ * arrives within the server's timeout. An error, an older Radar without the
29
+ * endpoint, or an "unknown" answer all leave the consent step as it was
30
+ * without the check.
31
+ */
32
+ export function useAgentSignin(agent: string, profile: ExecutionProfile, enabled: boolean): AgentSigninCheck {
33
+ const { support } = useRadarFeature('agentSigninCheck')
34
+ const active = enabled && !!agent && support !== 'unsupported'
35
+ const queryClient = useQueryClient()
36
+ const apiBase = getApiBase()
37
+ const query = useQuery({
38
+ queryKey: ['agent-signin', apiBase, agent, profile],
39
+ queryFn: ({ signal }) => fetchAgentSignin(agent, profile, false, signal),
40
+ enabled: active,
41
+ staleTime: SIGNIN_STALE_MS,
42
+ retry: false,
43
+ refetchOnWindowFocus: false,
44
+ })
45
+
46
+ // A click and a window-focus re-check can overlap; only the newest may
47
+ // apply its answer or clear the spinner.
48
+ const seq = useRef(0)
49
+ const [rechecking, setRechecking] = useState(false)
50
+ const recheck = useCallback(() => {
51
+ const key = ['agent-signin', apiBase, agent, profile]
52
+ const mine = ++seq.current
53
+ setRechecking(true)
54
+ void queryClient.cancelQueries({ queryKey: key, exact: true })
55
+ fetchAgentSignin(agent, profile, true)
56
+ .then((status) => {
57
+ if (mine === seq.current) queryClient.setQueryData(key, status)
58
+ })
59
+ .catch(() => {
60
+ // Unknown, not removed: a removed query refetches and the server's
61
+ // cache would hand back the stale "signed out".
62
+ if (mine === seq.current) queryClient.setQueryData(key, { agent, state: 'unknown' } satisfies AgentSigninStatus)
63
+ })
64
+ .finally(() => {
65
+ if (mine === seq.current) setRechecking(false)
66
+ })
67
+ }, [agent, profile, apiBase, queryClient])
68
+
69
+ const settle = useCallback(async () => {
70
+ if (!active) return undefined
71
+ const answer = queryClient
72
+ .fetchQuery({
73
+ queryKey: ['agent-signin', apiBase, agent, profile],
74
+ queryFn: ({ signal }) => fetchAgentSignin(agent, profile, false, signal),
75
+ staleTime: SIGNIN_STALE_MS,
76
+ retry: false,
77
+ })
78
+ .catch(() => undefined)
79
+ // The server answers within its own timeout, but a request can still sit
80
+ // in the browser's queue behind other connections; Approve must not.
81
+ let timer: ReturnType<typeof setTimeout> | undefined
82
+ const giveUp = new Promise<undefined>((resolve) => {
83
+ timer = setTimeout(() => resolve(undefined), SETTLE_MAX_MS)
84
+ })
85
+ try {
86
+ return await Promise.race([answer, giveUp])
87
+ } finally {
88
+ clearTimeout(timer)
89
+ }
90
+ }, [active, agent, profile, apiBase, queryClient])
91
+
92
+ const status = active && !query.isError ? query.data : undefined
93
+ const pending = active && query.isFetching && !query.data
94
+ const signedOut = status?.state === 'signed-out'
95
+ // Signing in happens in a terminal; coming back to the window is when to
96
+ // look again, as the agent list does after an install.
97
+ useEffect(() => {
98
+ if (!signedOut) return
99
+ const onFocus = () => recheck()
100
+ window.addEventListener('focus', onFocus)
101
+ return () => window.removeEventListener('focus', onFocus)
102
+ }, [signedOut, recheck])
103
+
104
+ return { status, pending, rechecking, recheck, settle }
105
+ }
106
+
107
+ /**
108
+ * Consent actions that respect a sign-in check still in flight. Approving
109
+ * before it answers would start the run the warning is there to prevent, so
110
+ * Approve waits for it (bounded by settle) and stops on a signed-out answer,
111
+ * which then shows; approving again proceeds. The wait belongs to one
112
+ * approval: Cancel, unmounting, or a new attemptKey (another agent, profile
113
+ * or consent request) abandons it, and its answer approves nothing.
114
+ */
115
+ export function useApproveAfterSignin({
116
+ approve,
117
+ cancel,
118
+ signin,
119
+ attemptKey,
120
+ }: {
121
+ approve: () => void
122
+ cancel: () => void
123
+ signin: Pick<AgentSigninCheck, 'pending' | 'settle'>
124
+ attemptKey: string
125
+ }) {
126
+ const [waiting, setWaiting] = useState(false)
127
+ const attempt = useRef(0)
128
+ const abandon = useCallback(() => {
129
+ attempt.current++
130
+ setWaiting(false)
131
+ }, [])
132
+ useEffect(() => abandon, [abandon, attemptKey])
133
+
134
+ // The approval in effect when the answer lands: the consent request may
135
+ // have been replaced by another target while waiting.
136
+ const latestApprove = useRef(approve)
137
+ useLayoutEffect(() => {
138
+ latestApprove.current = approve
139
+ }, [approve])
140
+ const { pending, settle } = signin
141
+ const approveWhenChecked = useCallback(() => {
142
+ if (!pending) {
143
+ latestApprove.current()
144
+ return
145
+ }
146
+ const mine = ++attempt.current
147
+ setWaiting(true)
148
+ void settle().then((status) => {
149
+ if (mine !== attempt.current) return
150
+ setWaiting(false)
151
+ if (status?.state !== 'signed-out') latestApprove.current()
152
+ })
153
+ }, [pending, settle])
154
+ const cancelAndAbandon = useCallback(() => {
155
+ abandon()
156
+ cancel()
157
+ }, [abandon, cancel])
158
+
159
+ return { approve: approveWhenChecked, cancel: cancelAndAbandon, waiting }
160
+ }
@@ -0,0 +1,108 @@
1
+ // @vitest-environment jsdom
2
+ import { act } from 'react'
3
+ import { createRoot, type Root } from 'react-dom/client'
4
+ import { beforeEach, expect, it, vi } from 'vitest'
5
+ import { useApproveAfterSignin } from './useAgentSignin'
6
+ import type { AgentSigninStatus } from '../api/diagnose'
7
+
8
+ vi.mock('../api/client', () => ({ useRadarFeature: () => ({ support: 'supported' }) }))
9
+ vi.mock('../api/diagnose', () => ({ fetchAgentSignin: vi.fn() }))
10
+
11
+ type Actions = ReturnType<typeof useApproveAfterSignin>
12
+ const seen = {} as { actions: Actions }
13
+
14
+ function Probe(props: Parameters<typeof useApproveAfterSignin>[0]) {
15
+ seen.actions = useApproveAfterSignin(props)
16
+ return null
17
+ }
18
+
19
+ function deferred() {
20
+ let resolve!: (s: AgentSigninStatus | undefined) => void
21
+ const promise = new Promise<AgentSigninStatus | undefined>((r) => { resolve = r })
22
+ return { promise, resolve }
23
+ }
24
+
25
+ const signedOut: AgentSigninStatus = { agent: 'claude', state: 'signed-out', signinCmd: 'claude auth login' }
26
+
27
+ let root: Root
28
+ let approve: ReturnType<typeof vi.fn<() => void>>
29
+ let cancel: ReturnType<typeof vi.fn<() => void>>
30
+
31
+ async function render(pending: boolean, settle: () => Promise<AgentSigninStatus | undefined>, attemptKey = 'claude:safeguarded') {
32
+ await act(async () => {
33
+ root.render(<Probe approve={approve} cancel={cancel} signin={{ pending, settle }} attemptKey={attemptKey} />)
34
+ })
35
+ }
36
+
37
+ beforeEach(() => {
38
+ Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
39
+ root = createRoot(document.createElement('div'))
40
+ approve = vi.fn()
41
+ cancel = vi.fn()
42
+ })
43
+
44
+ it('approves at once when no check is running', async () => {
45
+ const settle = vi.fn()
46
+ await render(false, settle)
47
+ await act(async () => seen.actions.approve())
48
+ expect(approve).toHaveBeenCalledTimes(1)
49
+ expect(settle).not.toHaveBeenCalled()
50
+ root.unmount()
51
+ })
52
+
53
+ it('waits for a running check and stops on signed out', async () => {
54
+ const answer = deferred()
55
+ await render(true, () => answer.promise)
56
+ await act(async () => seen.actions.approve())
57
+ expect(seen.actions.waiting).toBe(true)
58
+ expect(approve).not.toHaveBeenCalled()
59
+ await act(async () => answer.resolve(signedOut))
60
+ expect(seen.actions.waiting).toBe(false)
61
+ expect(approve).not.toHaveBeenCalled()
62
+ root.unmount()
63
+ })
64
+
65
+ it.each<[string, AgentSigninStatus | undefined]>([
66
+ ['signed in', { agent: 'claude', state: 'signed-in' }],
67
+ ['unknown', { agent: 'claude', state: 'unknown' }],
68
+ ['no answer (timeout or failure)', undefined],
69
+ ])('approves after a running check answers %s', async (_label, status) => {
70
+ const answer = deferred()
71
+ await render(true, () => answer.promise)
72
+ await act(async () => seen.actions.approve())
73
+ await act(async () => answer.resolve(status))
74
+ expect(approve).toHaveBeenCalledTimes(1)
75
+ root.unmount()
76
+ })
77
+
78
+ it('Cancel abandons the wait', async () => {
79
+ const answer = deferred()
80
+ await render(true, () => answer.promise)
81
+ await act(async () => seen.actions.approve())
82
+ await act(async () => seen.actions.cancel())
83
+ expect(cancel).toHaveBeenCalledTimes(1)
84
+ expect(seen.actions.waiting).toBe(false)
85
+ await act(async () => answer.resolve({ agent: 'claude', state: 'signed-in' }))
86
+ expect(approve).not.toHaveBeenCalled()
87
+ root.unmount()
88
+ })
89
+
90
+ it('switching agent or profile abandons the wait', async () => {
91
+ const answer = deferred()
92
+ await render(true, () => answer.promise)
93
+ await act(async () => seen.actions.approve())
94
+ await render(true, () => answer.promise, 'codex:safeguarded')
95
+ expect(seen.actions.waiting).toBe(false)
96
+ await act(async () => answer.resolve(undefined))
97
+ expect(approve).not.toHaveBeenCalled()
98
+ root.unmount()
99
+ })
100
+
101
+ it('leaving the card abandons the wait', async () => {
102
+ const answer = deferred()
103
+ await render(true, () => answer.promise)
104
+ await act(async () => seen.actions.approve())
105
+ root.unmount()
106
+ await act(async () => answer.resolve(undefined))
107
+ expect(approve).not.toHaveBeenCalled()
108
+ })