@skyhook-io/radar-app 1.22.2 → 1.23.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 (196) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +35 -10
  3. package/src/RadarApp.basename.test.tsx +177 -0
  4. package/src/RadarApp.settings.test.tsx +33 -0
  5. package/src/api/agentSandbox.ts +259 -0
  6. package/src/api/client.autoPromConnect.test.tsx +43 -0
  7. package/src/api/client.metricsRelayCheck.test.tsx +134 -0
  8. package/src/api/client.ts +122 -24
  9. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  10. package/src/api/diagnose.ts +4 -0
  11. package/src/api/kagent.test.ts +82 -0
  12. package/src/api/kagent.ts +230 -0
  13. package/src/api/prometheusCharts.ts +5 -0
  14. package/src/api/radarFeatures.test.ts +9 -0
  15. package/src/api/radarFeatures.ts +13 -0
  16. package/src/api/substrateWorkspace.test.ts +72 -0
  17. package/src/api/substrateWorkspace.ts +1394 -0
  18. package/src/api/vulnerabilities.ts +207 -9
  19. package/src/api/workloadSource.test.tsx +315 -0
  20. package/src/api/workloadSource.ts +128 -12
  21. package/src/components/CloudConnectFlow.tsx +46 -7
  22. package/src/components/CloudFunnelButton.test.tsx +193 -7
  23. package/src/components/CloudFunnelButton.tsx +127 -32
  24. package/src/components/SelfManagedStart.tsx +12 -2
  25. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  26. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  27. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  28. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  29. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  30. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  31. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  32. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  33. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  34. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  35. package/src/components/agentsandbox/data.ts +135 -0
  36. package/src/components/agentsandbox/host.test.ts +27 -0
  37. package/src/components/agentsandbox/host.tsx +85 -0
  38. package/src/components/agentsandbox/labels.test.ts +42 -0
  39. package/src/components/agentsandbox/labels.ts +146 -0
  40. package/src/components/agentsandbox/listFilters.ts +85 -0
  41. package/src/components/agentsandbox/lists.ts +52 -0
  42. package/src/components/agentsandbox/routes.ts +23 -0
  43. package/src/components/agentsandbox/shared.tsx +321 -0
  44. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  45. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  46. package/src/components/agentsandbox/workspace.tsx +258 -0
  47. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  48. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  49. package/src/components/applications/ApplicationsView.tsx +156 -3
  50. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  51. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  52. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  53. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  54. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  55. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  56. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  57. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  58. package/src/components/cloudHints/cloudHints.ts +131 -0
  59. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  60. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  61. package/src/components/cloudHints/cloudLinks.ts +31 -0
  62. package/src/components/cloudHints/hintStorage.ts +28 -0
  63. package/src/components/cnpg/CNPGView.tsx +4 -7
  64. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  65. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  66. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  67. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  68. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  69. package/src/components/home/HomeAgentBlock.tsx +2 -0
  70. package/src/components/home/HomeView.tsx +3 -3
  71. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  72. package/src/components/home/MCPSetupDialog.tsx +6 -2
  73. package/src/components/home/McpCloudLine.test.tsx +162 -0
  74. package/src/components/home/McpCloudLine.tsx +95 -0
  75. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  76. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  77. package/src/components/home/mcpToolCatalog.ts +4 -4
  78. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  79. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  80. package/src/components/issues/IssuesPane.tsx +181 -23
  81. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  82. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  83. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  84. package/src/components/issues/sinceLastVisit.ts +439 -0
  85. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  86. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  87. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  88. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  89. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  90. package/src/components/kagent/KagentLists.tsx +412 -0
  91. package/src/components/kagent/KagentOverview.tsx +234 -0
  92. package/src/components/kagent/KagentPages.tsx +690 -0
  93. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  94. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  95. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  96. package/src/components/kagent/KagentView.tsx +109 -0
  97. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  98. package/src/components/kagent/host.tsx +144 -0
  99. package/src/components/kagent/routes.ts +31 -0
  100. package/src/components/kagent/shared.tsx +336 -0
  101. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  102. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  103. package/src/components/kagent/workspace.fixtures.ts +108 -0
  104. package/src/components/kagent/workspaceRoute.ts +18 -0
  105. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  106. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  107. package/src/components/resource/PrometheusCharts.tsx +10 -1
  108. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  109. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  110. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  111. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  112. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  113. package/src/components/resources/ResourcesView.tsx +2 -6
  114. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  115. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  116. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  117. package/src/components/settings/SettingsDialog.tsx +84 -16
  118. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  119. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  120. package/src/components/settings/SubstrateSettings.tsx +544 -0
  121. package/src/components/settings/settings-state.test.ts +21 -3
  122. package/src/components/settings/settings-state.ts +13 -3
  123. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  124. package/src/components/share/ShareLinkButton.tsx +391 -0
  125. package/src/components/share/openShareInCloud.test.ts +29 -0
  126. package/src/components/share/openShareInCloud.ts +10 -0
  127. package/src/components/share/shareLink.test.ts +129 -0
  128. package/src/components/share/shareLink.ts +175 -0
  129. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  130. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  131. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  132. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  133. package/src/components/substrate/SubstrateActors.tsx +612 -0
  134. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  135. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  136. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  137. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  138. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  139. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  140. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  141. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  142. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  143. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  144. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  145. package/src/components/substrate/SubstrateView.tsx +173 -0
  146. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  147. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  148. package/src/components/substrate/attention.ts +81 -0
  149. package/src/components/substrate/contextPin.tsx +69 -0
  150. package/src/components/substrate/host.tsx +83 -0
  151. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  152. package/src/components/substrate/readings.test.ts +484 -0
  153. package/src/components/substrate/readings.ts +997 -0
  154. package/src/components/substrate/routes.ts +103 -0
  155. package/src/components/substrate/shared.tsx +426 -0
  156. package/src/components/substrate/substrate.fixtures.ts +325 -0
  157. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  158. package/src/components/substrate/workspaceRoute.ts +23 -0
  159. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  160. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  161. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  162. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  163. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  164. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  165. package/src/components/traffic/TrafficGraph.tsx +17 -14
  166. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  167. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  168. package/src/components/traffic/TrafficView.tsx +26 -56
  169. package/src/components/traffic/trafficFilters.test.ts +61 -1
  170. package/src/components/traffic/trafficFilters.ts +68 -8
  171. package/src/components/velero/VeleroOverview.tsx +2 -2
  172. package/src/components/velero/VeleroView.tsx +3 -6
  173. package/src/components/vulnerabilities/columns.tsx +132 -0
  174. package/src/components/vulnerabilities/filters.tsx +317 -0
  175. package/src/components/vulnerabilities/owner.test.ts +54 -0
  176. package/src/components/vulnerabilities/owner.tsx +163 -0
  177. package/src/components/vulnerabilities/parts.test.ts +126 -12
  178. package/src/components/vulnerabilities/parts.tsx +612 -52
  179. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  180. package/src/components/vulnerabilities/traffic.tsx +40 -0
  181. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  182. package/src/components/workload/WorkloadView.tsx +52 -13
  183. package/src/components/workspace/layout.tsx +13 -7
  184. package/src/components/workspace/sidebar.test.ts +48 -0
  185. package/src/components/workspace/sidebar.ts +73 -3
  186. package/src/components/workspace/table.ts +2 -1
  187. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  188. package/src/contexts/RegistryAccessMode.tsx +25 -0
  189. package/src/integrations/resourceHost.ts +12 -6
  190. package/src/integrations/resourceHosts.test.tsx +27 -1
  191. package/src/integrations/resourceHosts.tsx +15 -7
  192. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  193. package/src/integrations/sidebarWorkspaces.ts +41 -0
  194. package/src/integrations/workspaceRoute.ts +1 -1
  195. package/src/integrations/workspaceRoutes.ts +7 -1
  196. package/src/integrations/workspaceScreens.tsx +6 -0
@@ -0,0 +1,966 @@
1
+ import { useMemo } from 'react'
2
+ import { useSearchParams } from 'react-router-dom'
3
+ import { Plus } from 'lucide-react'
4
+ import { PaneLoader, SearchBox, Tooltip, toneTextClass, type StatusBadge } from '@skyhook-io/k8s-ui'
5
+ import { formatAge, summarizeSchedulerMessage } from '@skyhook-io/k8s-ui/components/resources/resource-utils'
6
+ import { useMediaQuery } from '../../hooks/useMediaQuery'
7
+ import {
8
+ getAgentRuntimeStatus,
9
+ getSandboxWarmPoolReadyOfDesired,
10
+ getSandboxClaimStatus,
11
+ getSandboxClaimWarmPool,
12
+ getSandboxExpiry,
13
+ getSandboxOperatingMode,
14
+ getSandboxStatus,
15
+ getSandboxWarmPoolStatus,
16
+ getSandboxWarmPoolTemplate,
17
+ sandboxPodName,
18
+ } from '@skyhook-io/k8s-ui/components/resources/resource-utils-agent-runtimes'
19
+ import type { SelectedResource } from '../../types'
20
+ import { ScreenBody, SectionTable, Segments, Sub, type TableColumn } from '../workspace/layout'
21
+ import { useWorkspaceNavigate } from '../workspace/useWorkspaceNavigate'
22
+ import { claimSandboxName, poolClaims, sandboxController } from './lists'
23
+ import { notReadyMembers, objectKey, schedulerReason, warmPoolBadge, type ServerReadings } from './labels'
24
+ import type { KindRead } from './data'
25
+ import { readInNamespace, readItems } from './data'
26
+ import { AGENT_SANDBOX_EXTENSIONS_GROUP, AGENT_SANDBOX_GROUP, SANDBOXES_PATH, SANDBOX_CLAIMS_PATH, SANDBOX_CLAIM_KIND, SANDBOX_KIND, SANDBOX_WARM_POOL_KIND } from './routes'
27
+ import { useListFilters } from './listFilters'
28
+ import {
29
+ AGENT_SANDBOX_WIDE,
30
+ AgentSandboxCoverageNotice,
31
+ AgentSandboxHeader,
32
+ Absent,
33
+ ExpiryCell,
34
+ ObjectName,
35
+ ReadingBadge,
36
+ RowLink,
37
+ agentSandboxResource,
38
+ coverageEmptyText,
39
+ type AgentSandboxScreenProps,
40
+ } from './shared'
41
+
42
+ const ns = (o: any): string => o?.metadata?.namespace ?? ''
43
+ const nm = (o: any): string => o?.metadata?.name ?? ''
44
+ const rowKey = (o: any) => `${ns(o)}/${nm(o)}`
45
+ const manyNamespaces = (rows: any[]) => new Set(rows.map(ns)).size > 1
46
+
47
+ function singleNamespaceOf(rows: any[]): string | undefined {
48
+ const seen = new Set(rows.map(ns).filter(Boolean))
49
+ return seen.size === 1 ? [...seen][0] : undefined
50
+ }
51
+
52
+ function isPartialRead(read: KindRead): boolean {
53
+ return read.state === 'read' && read.coverage.status === 'partial'
54
+ }
55
+
56
+ const countBadge = (n: number, partial: boolean) => (partial ? `≥${n}` : n)
57
+
58
+ const RANK: Record<StatusBadge['level'], number> = { unhealthy: 0, alert: 1, degraded: 2, unknown: 3, healthy: 4, neutral: 5 }
59
+
60
+ const INSPECTED_NAME_WIDTH = 'clamp(9rem, 11.25vw, 13rem)'
61
+ const INSPECTED_STATE_WIDTH = 'clamp(10.5rem, 13vw, 16rem)'
62
+
63
+ function useTableLayout(inspected: SelectedResource | null) {
64
+ const wide = useMediaQuery(AGENT_SANDBOX_WIDE)
65
+ // A secondary column takes spare width so the fixed columns stay to the left of the overlay.
66
+ const roomy = useMediaQuery('(min-width: 1600px)')
67
+ return { wide, compact: !!inspected && !roomy }
68
+ }
69
+
70
+ /** Rows that need a look first (using the server's escalated tone when present), then by namespace and name. */
71
+ function byReading(rows: any[], levelOf: (row: any) => StatusBadge['level']): any[] {
72
+ return [...rows].sort((a, b) => {
73
+ const r = RANK[levelOf(a)] - RANK[levelOf(b)]
74
+ if (r !== 0) return r
75
+ return rowKey(a).localeCompare(rowKey(b))
76
+ })
77
+ }
78
+
79
+ function NameCell({ o, multi }: { o: any; multi: boolean }) {
80
+ return (
81
+ <>
82
+ <ObjectName name={nm(o)} />
83
+ {multi && <Sub>{ns(o)}</Sub>}
84
+ </>
85
+ )
86
+ }
87
+
88
+ /**
89
+ * What the user asked for in spec.operatingMode, only where the state hasn't
90
+ * caught up with it: a suspension asked for and not done, or a resume. An
91
+ * expired or failed Sandbox stays "Running" in its spec, which says nothing.
92
+ */
93
+ export function requestedMode(o: any): string | undefined {
94
+ const mode = getSandboxOperatingMode(o)
95
+ const text = getSandboxStatus(o).text
96
+ // Suspending and Suspension blocked already say a suspension was asked for.
97
+ if (mode === 'Suspended' && !['Suspended', 'Suspending', 'Suspension blocked'].includes(text)) return 'suspended'
98
+ if (mode !== 'Suspended' && (text === 'Suspended' || text === 'Suspending')) return mode.toLowerCase()
99
+ return undefined
100
+ }
101
+
102
+ const letters = (t: string) => t.toLowerCase().replace(/[^a-z]/g, '')
103
+
104
+ /**
105
+ * One readable reason under a reading in a table row: the scheduler's verdict
106
+ * in plain words, a concise suspension-conflict summary, a stripped container
107
+ * waiting reason, or the controller's message. Nothing for a settled state.
108
+ */
109
+ export function stateMessage(o: any, status: StatusBadge): string | undefined {
110
+ if (status.level === 'healthy' || status.level === 'neutral') return undefined
111
+ const scheduled = Array.isArray(o?.status?.conditions) ? o.status.conditions.find((c: any) => c?.type === 'PodScheduled') : undefined
112
+ if (scheduled?.status === 'False' && scheduled.reason === status.text && scheduled.message) {
113
+ const plain = summarizeSchedulerMessage(scheduled.message, { plain: true })
114
+ if (plain) return `${plain[0].toUpperCase()}${plain.slice(1)}`
115
+ }
116
+ if (status.text === 'Suspension blocked') {
117
+ const podName = sandboxPodName(o)
118
+ return podName ? `Conflicting Pod "${podName}" is not owned by this Sandbox` : 'Conflicting Pod is not owned by this Sandbox'
119
+ }
120
+ if (status.text === 'PodFailed') {
121
+ return 'Pod exited with failure.'
122
+ }
123
+ const message = getAgentRuntimeStatus(o)?.message
124
+ if (!message || letters(message) === letters(status.text)) return undefined
125
+ // Strip noisy controller boilerplate so container waiting reasons stay short and readable.
126
+ const stripped = message.replace(/^Pod exists with phase:\s*Pending;\s*/i, '')
127
+ return stripped ? `${stripped[0].toUpperCase()}${stripped.slice(1)}` : message
128
+ }
129
+
130
+ /** The reading, with what explains it under it, unless another column already says it. */
131
+ function StateCell({ o, status, requested, level, hideMessage, compact }: { o: any; status: StatusBadge; requested?: string; level?: StatusBadge['level']; hideMessage?: boolean; compact: boolean }) {
132
+ const message = hideMessage ? undefined : stateMessage(o, status)
133
+ const rawMessage = hideMessage ? undefined : getAgentRuntimeStatus(o)?.message
134
+ return (
135
+ <>
136
+ <span className="inline-flex flex-wrap items-center gap-x-1.5">
137
+ <ReadingBadge status={status} level={level} />
138
+ {requested && <span className="text-xs text-theme-text-tertiary">requested {requested}</span>}
139
+ </span>
140
+ {message && (
141
+ <Sub>
142
+ <Tooltip content={rawMessage || message}><span className="break-words">{compact && status.text === 'Suspension blocked' ? 'Sandbox doesn’t own the Pod' : message}</span></Tooltip>
143
+ </Sub>
144
+ )}
145
+ </>
146
+ )
147
+ }
148
+
149
+ function AgeCell({ o }: { o: any }) {
150
+ const created = o?.metadata?.creationTimestamp
151
+ return created ? <span className="text-sm text-theme-text-secondary">{formatAge(created)}</span> : <Absent>unknown</Absent>
152
+ }
153
+
154
+ function OpenCell() {
155
+ return <span className="whitespace-nowrap text-xs font-medium text-accent-text">Open →</span>
156
+ }
157
+
158
+ /** Narrow: the expiry with the age under it. */
159
+ function ExpiryAgeCell({ o, claimed }: { o: any; claimed?: boolean }) {
160
+ const created = o?.metadata?.creationTimestamp
161
+ return (
162
+ <>
163
+ <ExpiryCell resource={o} claimed={claimed} />
164
+ {created && <Sub>{formatAge(created)} old</Sub>}
165
+ </>
166
+ )
167
+ }
168
+
169
+ /**
170
+ * What owns a Sandbox, from its owner references: a claim or a warm pool,
171
+ * else what else owns it, else nothing. "standalone" only where every claim
172
+ * in its namespace was read, since a claim can name a Sandbox it doesn't own.
173
+ */
174
+ export function OwnerAbsent({ o, claims }: { o: any; claims: KindRead }) {
175
+ const refs: any[] = Array.isArray(o?.metadata?.ownerReferences) ? o.metadata.ownerReferences : []
176
+ const other = refs.find((r) => r?.controller) ?? refs[0]
177
+ if (other?.kind && other?.name) {
178
+ return (
179
+ <>
180
+ <ObjectName name={other.name} />
181
+ <Sub>{other.kind}</Sub>
182
+ </>
183
+ )
184
+ }
185
+ if (readInNamespace(claims, ns(o))) return <Absent title="No warm pool or claim owns it, and no claim names it.">standalone</Absent>
186
+ return <Absent title="No warm pool or claim owns it. Radar couldn’t read every claim here, so one may name it.">no warm pool; claims not read</Absent>
187
+ }
188
+
189
+ export function SandboxesTable({ read, claims: claimsRead, onInspect, inspected, title, server, empty }: { read: KindRead; claims: KindRead; onInspect: (r: SelectedResource) => void; inspected: SelectedResource | null; title?: string; server?: ServerReadings; empty?: string }) {
190
+ const rows = useMemo(
191
+ () => byReading(readItems(read), (o) => server?.tones.get(objectKey('Sandbox', ns(o), nm(o))) ?? getSandboxStatus(o).level),
192
+ [read, server],
193
+ )
194
+ const multi = manyNamespaces(rows)
195
+ // A Sandbox a claim names but doesn't own (adopted from a warm pool) still belongs to that claim.
196
+ const claimFor = useMemo(() => {
197
+ const m = new Map<string, any>()
198
+ for (const c of readItems(claimsRead)) {
199
+ const name = claimSandboxName(c)
200
+ if (name) m.set(`${ns(c)}/${name}`, c)
201
+ }
202
+ return m
203
+ }, [claimsRead])
204
+ const { wide, compact } = useTableLayout(inspected)
205
+ const ownerOf = (o: any) => {
206
+ const claim = claimFor.get(rowKey(o))
207
+ return claim ? { kind: 'SandboxClaim', group: AGENT_SANDBOX_EXTENSIONS_GROUP, namespace: ns(o), name: nm(claim) } : sandboxController(o)
208
+ }
209
+ const ownerWord = (owner: { kind: string }) => (owner.kind === 'SandboxClaim' ? 'claim' : 'warm pool')
210
+ // Narrow: the claim or pool under the name, the age under the expiry.
211
+ const columns: TableColumn<any>[] = [
212
+ {
213
+ header: 'Sandbox',
214
+ width: compact ? INSPECTED_NAME_WIDTH : wide ? '21%' : '29%',
215
+ cell: (o) => {
216
+ const owner = wide ? undefined : ownerOf(o)
217
+ return (
218
+ <>
219
+ <NameCell o={o} multi={multi} />
220
+ {owner && (
221
+ <Sub>
222
+ {ownerWord(owner)} <RowLink refTo={owner} onInspect={onInspect} inline />
223
+ </Sub>
224
+ )}
225
+ {!wide && !owner && (
226
+ <Sub>
227
+ <OwnerAbsent o={o} claims={claimsRead} />
228
+ </Sub>
229
+ )}
230
+ </>
231
+ )
232
+ },
233
+ },
234
+ { header: 'State', width: compact ? INSPECTED_STATE_WIDTH : wide ? '33%' : '41%', cell: (o) => <StateCell o={o} status={getSandboxStatus(o)} requested={requestedMode(o)} level={server?.tones.get(objectKey('Sandbox', ns(o), nm(o)))} compact={compact} /> },
235
+ ...(wide
236
+ ? [
237
+ {
238
+ header: 'Claim or pool',
239
+ width: compact ? undefined : '17%',
240
+ cell: (o: any) => {
241
+ const owner = ownerOf(o)
242
+ if (!owner) return <OwnerAbsent o={o} claims={claimsRead} />
243
+ return (
244
+ <>
245
+ <RowLink refTo={owner} onInspect={onInspect} />
246
+ <Sub>{ownerWord(owner)}</Sub>
247
+ </>
248
+ )
249
+ },
250
+ },
251
+ { header: 'Expiry', width: '14%', cell: (o: any) => <ExpiryCell resource={o} claimed={ownerOf(o)?.kind === 'SandboxClaim'} /> },
252
+ { header: 'Age', width: '8%', cell: (o: any) => <AgeCell o={o} /> },
253
+ ]
254
+ : [{ header: 'Expiry, age', width: compact ? undefined : '21%', cell: (o: any) => <ExpiryAgeCell o={o} claimed={ownerOf(o)?.kind === 'SandboxClaim'} /> }]),
255
+ { header: '', width: wide ? '7%' : '9%', className: 'text-right', cell: () => <OpenCell /> },
256
+ ]
257
+ return (
258
+ <SectionTable
259
+ title={title}
260
+ columns={columns}
261
+ rows={rows}
262
+ rowKey={rowKey}
263
+ rowResource={(o) => agentSandboxResource({ kind: 'Sandbox', group: AGENT_SANDBOX_GROUP, namespace: ns(o), name: nm(o) })}
264
+ onInspect={onInspect}
265
+ inspected={inspected}
266
+ empty={empty ?? coverageEmptyText(read, 'Sandboxes', 'sandboxes')}
267
+ minWidth={wide ? 760 : 560}
268
+ />
269
+ )
270
+ }
271
+
272
+ /** The claim's state is the controller's WarmPoolNotFound. */
273
+ export function reportsMissingPool(o: any): boolean {
274
+ return getSandboxClaimStatus(o).text === 'WarmPoolNotFound'
275
+ }
276
+
277
+ export function ClaimsTable({ read, warmPools, onInspect, inspected, server, empty }: { read: KindRead; warmPools: KindRead; onInspect: (r: SelectedResource) => void; inspected: SelectedResource | null; server?: ServerReadings; empty?: string }) {
278
+ const rows = useMemo(
279
+ () => byReading(readItems(read), (o) => server?.tones.get(objectKey('SandboxClaim', ns(o), nm(o))) ?? getSandboxClaimStatus(o).level),
280
+ [read, server],
281
+ )
282
+ const multi = manyNamespaces(rows)
283
+ const pools = useMemo(() => new Set(readItems(warmPools).map(rowKey)), [warmPools])
284
+ const { wide, compact } = useTableLayout(inspected)
285
+ const sandboxOf = (o: any) => {
286
+ const name = claimSandboxName(o)
287
+ return name ? { kind: 'Sandbox', group: AGENT_SANDBOX_GROUP, namespace: ns(o), name } : undefined
288
+ }
289
+ const poolCell = (o: any) => {
290
+ const pool = getSandboxClaimWarmPool(o)
291
+ if (pool === '-') return <Absent>no warm pool</Absent>
292
+ const ref = { kind: 'SandboxWarmPool', group: AGENT_SANDBOX_EXTENSIONS_GROUP, namespace: ns(o), name: pool }
293
+ // A pool Radar didn't find is named, not linked: "not found" only where
294
+ // every warm pool in the namespace was read, else "not read".
295
+ if (!pools.has(`${ns(o)}/${pool}`)) {
296
+ const absent = readInNamespace(warmPools, ns(o))
297
+ return (
298
+ <>
299
+ <ObjectName name={pool} />
300
+ <Sub>
301
+ <span className={absent ? toneTextClass('unhealthy') : undefined}>{absent ? 'not found' : 'not read'}</span>
302
+ </Sub>
303
+ </>
304
+ )
305
+ }
306
+ return <RowLink refTo={ref} onInspect={onInspect} />
307
+ }
308
+ const bindingCell = (o: any) => {
309
+ const sb = sandboxOf(o)
310
+ if (sb) return <RowLink refTo={sb} onInspect={onInspect} />
311
+ if (getSandboxClaimStatus(o).text === 'Expired') {
312
+ return <Absent title="This claim expired without a bound Sandbox listed in status.">not bound (expired)</Absent>
313
+ }
314
+ return <Absent title="The claim’s status names no Sandbox now.">not bound</Absent>
315
+ }
316
+
317
+ const columns: TableColumn<any>[] = [
318
+ { header: 'Claim', width: compact ? INSPECTED_NAME_WIDTH : wide ? '19%' : '20%', cell: (o) => <NameCell o={o} multi={multi} /> },
319
+ { header: 'State', width: compact ? INSPECTED_STATE_WIDTH : wide ? '25%' : '30%', cell: (o) => <StateCell o={o} status={getSandboxClaimStatus(o)} level={server?.tones.get(objectKey('SandboxClaim', ns(o), nm(o)))} hideMessage={reportsMissingPool(o)} compact={compact} /> },
320
+ { header: 'Warm pool & binding', width: compact ? undefined : wide ? '31%' : '24%', cell: (o) => (
321
+ <div className="space-y-1">
322
+ {poolCell(o)}
323
+ <Sub>{bindingCell(o)}</Sub>
324
+ </div>
325
+ ) },
326
+ ...(wide
327
+ ? [
328
+ { header: 'Expiry', width: '11%', cell: (o: any) => <ExpiryCell resource={o} /> },
329
+ { header: 'Age', width: '7%', cell: (o: any) => <AgeCell o={o} /> },
330
+ ]
331
+ : [{ header: 'Expiry, age', width: '17%', cell: (o: any) => <ExpiryAgeCell o={o} /> }]),
332
+ { header: '', width: wide ? '7%' : '9%', className: 'text-right', cell: () => <OpenCell /> },
333
+ ]
334
+ return (
335
+ <SectionTable
336
+ columns={columns}
337
+ rows={rows}
338
+ rowKey={rowKey}
339
+ rowResource={(o) => agentSandboxResource({ kind: 'SandboxClaim', group: AGENT_SANDBOX_EXTENSIONS_GROUP, namespace: ns(o), name: nm(o) })}
340
+ onInspect={onInspect}
341
+ inspected={inspected}
342
+ empty={empty ?? coverageEmptyText(read, 'SandboxClaims', 'claims')}
343
+ minWidth={wide ? 760 : 560}
344
+ />
345
+ )
346
+ }
347
+
348
+ /** The Claims list narrowed to claims referencing one warm pool. */
349
+ export function poolClaimsPath(namespace: string, name: string): string {
350
+ return `${SANDBOX_CLAIMS_PATH}&pool=${encodeURIComponent(`${namespace}/${name}`)}`
351
+ }
352
+
353
+ export function WarmPoolsTable({
354
+ read,
355
+ claims,
356
+ claimsRead,
357
+ onInspect,
358
+ inspected,
359
+ title,
360
+ server,
361
+ empty,
362
+ }: {
363
+ read: KindRead
364
+ claims: any[]
365
+ claimsRead: KindRead
366
+ onInspect: (r: SelectedResource) => void
367
+ inspected: SelectedResource | null
368
+ title?: string
369
+ /** What the server's summary says about these pools. */
370
+ server?: ServerReadings
371
+ empty?: string
372
+ }) {
373
+ const navigate = useWorkspaceNavigate()
374
+ const rows = useMemo(
375
+ () => byReading(readItems(read), (o) => server?.tones.get(objectKey('SandboxWarmPool', ns(o), nm(o))) ?? getSandboxWarmPoolStatus(o).level),
376
+ [read, server],
377
+ )
378
+ const multi = manyNamespaces(rows)
379
+ const { wide, compact } = useTableLayout(inspected)
380
+ // Narrow: ready of desired under the state, the age under the name.
381
+ const columns: TableColumn<any>[] = [
382
+ {
383
+ header: 'Warm pool',
384
+ width: compact ? INSPECTED_NAME_WIDTH : wide ? '19%' : '24%',
385
+ cell: (o) => (
386
+ <>
387
+ <NameCell o={o} multi={multi} />
388
+ {!wide && o?.metadata?.creationTimestamp && <Sub>{formatAge(o.metadata.creationTimestamp)} old</Sub>}
389
+ </>
390
+ ),
391
+ },
392
+ {
393
+ header: 'State',
394
+ width: compact ? INSPECTED_STATE_WIDTH : wide ? '24%' : '28%',
395
+ cell: (o) => (
396
+ <>
397
+ <PoolStateBadge o={o} server={server} />
398
+ <PoolStateDetail o={o} server={server} compact={compact} />
399
+ {!wide && <Sub>{getSandboxWarmPoolReadyOfDesired(o)} ready</Sub>}
400
+ </>
401
+ ),
402
+ },
403
+ ...(wide
404
+ ? [
405
+ {
406
+ header: 'Ready',
407
+ width: '10%',
408
+ cell: (o: any) => (
409
+ <>
410
+ <span className="font-mono text-sm">{getSandboxWarmPoolReadyOfDesired(o)}</span>
411
+ <Sub>of desired</Sub>
412
+ </>
413
+ ),
414
+ },
415
+ ]
416
+ : []),
417
+ {
418
+ header: 'Template',
419
+ width: compact ? undefined : wide ? '17%' : '20%',
420
+ cell: (o) => {
421
+ const t = getSandboxWarmPoolTemplate(o)
422
+ if (t === '-') return <Absent>no template</Absent>
423
+ const key = objectKey('SandboxWarmPool', ns(o), nm(o))
424
+ const pool = server?.warmPools.get(key)
425
+ const rel = server?.rows.get(key)?.relations?.find((r) => r.role === 'template' && r.ref.name === t)
426
+ const presence = rel?.presence ?? (pool?.template === t ? pool.templatePresence : undefined)
427
+ if (presence !== 'present') {
428
+ return (
429
+ <>
430
+ <ObjectName name={t} />
431
+ <Sub>
432
+ <span className={presence === 'absent' ? toneTextClass('unhealthy') : undefined}>{presence === 'absent' ? 'not found' : 'not read'}</span>
433
+ </Sub>
434
+ </>
435
+ )
436
+ }
437
+ return <RowLink refTo={{ kind: 'SandboxTemplate', group: AGENT_SANDBOX_EXTENSIONS_GROUP, namespace: ns(o), name: t }} onInspect={onInspect} />
438
+ },
439
+ },
440
+ {
441
+ header: 'Claims referencing',
442
+ width: wide ? '17%' : '19%',
443
+ cell: (o) => {
444
+ if (!readInNamespace(claimsRead, ns(o))) return <Absent>unknown</Absent>
445
+ const served = poolClaims(o, claims)
446
+ if (served.length === 0) return <Absent>none</Absent>
447
+ const bound = served.filter((c) => claimSandboxName(c) && getSandboxClaimStatus(c).text !== 'Expired').length
448
+ const expired = served.filter((c) => getSandboxClaimStatus(c).text === 'Expired').length
449
+ const detail = expired > 0 ? `${bound} currently bound · ${expired} expired` : `${bound} currently bound`
450
+ return (
451
+ <>
452
+ <button
453
+ type="button"
454
+ onClick={(e) => {
455
+ e.stopPropagation()
456
+ navigate(poolClaimsPath(ns(o), nm(o)))
457
+ }}
458
+ onKeyDown={(e) => e.stopPropagation()}
459
+ className="text-left text-sm text-accent-text hover:underline"
460
+ >
461
+ {served.length} referencing
462
+ </button>
463
+ <Sub>{detail}</Sub>
464
+ </>
465
+ )
466
+ },
467
+ },
468
+ ...(wide ? [{ header: 'Age', width: '7%', cell: (o: any) => <AgeCell o={o} /> }] : []),
469
+ { header: '', width: wide ? '7%' : '9%', className: 'text-right', cell: () => <OpenCell /> },
470
+ ]
471
+ return (
472
+ <SectionTable
473
+ title={title}
474
+ columns={columns}
475
+ rows={rows}
476
+ rowKey={rowKey}
477
+ rowResource={(o) => agentSandboxResource({ kind: 'SandboxWarmPool', group: AGENT_SANDBOX_EXTENSIONS_GROUP, namespace: ns(o), name: nm(o) })}
478
+ onInspect={onInspect}
479
+ inspected={inspected}
480
+ empty={empty ?? coverageEmptyText(read, 'SandboxWarmPools', 'warmPools')}
481
+ minWidth={wide ? 760 : 560}
482
+ />
483
+ )
484
+ }
485
+
486
+ /** One canonical warm pool badge reading, shared with the drawer/page header pill. */
487
+ function PoolStateBadge({ o, server }: { o: any; server?: ServerReadings }) {
488
+ const b = warmPoolBadge(o, server)
489
+ return <ReadingBadge status={b.status} label={b.label} level={b.level} title={b.title} />
490
+ }
491
+
492
+ /** The Sandboxes list narrowed to one warm pool's sandboxes that aren't ready. */
493
+ export function poolNotReadyPath(namespace: string, name: string): string {
494
+ return `${SANDBOXES_PATH}&pool=${encodeURIComponent(`${namespace}/${name}`)}&state=notReady`
495
+ }
496
+
497
+ /**
498
+ * Under a pool's state, from the server's row about it: the cause (e.g.
499
+ * scheduler verdict in plain words) and the sandboxes it names as not ready.
500
+ */
501
+ function PoolStateDetail({ o, server, compact }: { o: any; server?: ServerReadings; compact: boolean }) {
502
+ const navigate = useWorkspaceNavigate()
503
+ const row = server?.rows.get(objectKey('SandboxWarmPool', ns(o), nm(o)))
504
+ const reason = schedulerReason(row)
505
+ const members = notReadyMembers(row)
506
+ return (
507
+ <>
508
+ {reason && (
509
+ <Sub>
510
+ <Tooltip content={reason.raw}><span>{compact ? reason.plain : `Can’t schedule · ${reason.plain}`}</span></Tooltip>
511
+ </Sub>
512
+ )}
513
+ {!reason && row?.rule === 'reserveBelowTarget' && row.reading && (
514
+ <Sub>
515
+ <Tooltip content={row.reading}><span>{row.reading}</span></Tooltip>
516
+ </Sub>
517
+ )}
518
+ {members.length > 0 && (
519
+ <Sub>
520
+ <button
521
+ type="button"
522
+ onClick={(e) => {
523
+ e.stopPropagation()
524
+ navigate(poolNotReadyPath(ns(o), nm(o)))
525
+ }}
526
+ onKeyDown={(e) => e.stopPropagation()}
527
+ className="text-accent-text hover:underline"
528
+ >
529
+ Show all members that aren’t ready
530
+ </button>
531
+ </Sub>
532
+ )}
533
+ </>
534
+ )
535
+ }
536
+
537
+ function CreateButton({ onCreate, label }: { onCreate?: () => void; label: string }) {
538
+ if (!onCreate) return null
539
+ return (
540
+ <button type="button" onClick={onCreate} className="btn-secondary inline-flex items-center gap-1.5 px-2.5 py-1 text-xs">
541
+ <Plus className="h-3.5 w-3.5" />
542
+ Create {label}
543
+ </button>
544
+ )
545
+ }
546
+
547
+ /**
548
+ * The Sandboxes list's own filters, from the URL: `pool` (namespace/name)
549
+ * keeps one warm pool's sandboxes, `state=notReady` those whose reading
550
+ * isn't Ready, `state=expired` those whose reading is Expired.
551
+ */
552
+ export function filterSandboxes(read: KindRead, pool: string, state: string): KindRead {
553
+ if (read.state !== 'read' || (!pool && state !== 'notReady' && state !== 'expired' && state !== 'recentlyExpired')) return read
554
+ const items = read.items.filter((o) => {
555
+ if (pool) {
556
+ const owner = sandboxController(o)
557
+ if (owner?.kind !== 'SandboxWarmPool' || `${owner.namespace}/${owner.name}` !== pool) return false
558
+ }
559
+ if (state === 'notReady') return getSandboxStatus(o).level !== 'healthy'
560
+ if (state === 'expired') return getSandboxStatus(o).text === 'Expired'
561
+ if (state === 'recentlyExpired') return getSandboxStatus(o).text === 'Expired' && recentlyExpired(o)
562
+ return true
563
+ })
564
+ return { ...read, items }
565
+ }
566
+
567
+ /** Keeps the objects whose name contains `search`, ignoring case. */
568
+ function recentlyExpired(o: any): boolean {
569
+ const expiry = getSandboxExpiry(o)
570
+ if (!expiry) return false
571
+ const elapsed = Date.now() - Date.parse(expiry)
572
+ return elapsed >= 0 && elapsed <= 7 * 24 * 60 * 60 * 1000
573
+ }
574
+
575
+ export function filterByName(read: KindRead, search: string): KindRead {
576
+ const q = search.trim().toLowerCase()
577
+ if (read.state !== 'read' || !q) return read
578
+ return { ...read, items: read.items.filter((o) => nm(o).toLowerCase().includes(q)) }
579
+ }
580
+
581
+ function filterItems(read: KindRead, predicate: (o: any) => boolean): KindRead {
582
+ if (read.state !== 'read') return read
583
+ return { ...read, items: read.items.filter(predicate) }
584
+ }
585
+
586
+ /** The list's name search, kept in the Resources page's own `search` URL param so its links narrow these lists too. */
587
+ function useNameSearch(): [string, (value: string) => void] {
588
+ const [params, setParams] = useSearchParams()
589
+ const set = (value: string) => {
590
+ const p = new URLSearchParams(params)
591
+ if (value) p.set('search', value)
592
+ else p.delete('search')
593
+ setParams(p, { replace: true })
594
+ }
595
+ return [params.get('search') ?? '', set]
596
+ }
597
+
598
+ function useUrlParam<T extends string>(key: string, valid: readonly T[], fallback: T): [T, (value: T) => void] {
599
+ const [params, setParams] = useSearchParams()
600
+ const raw = params.get(key)
601
+ const value = raw && (valid as readonly string[]).includes(raw) ? (raw as T) : fallback
602
+ const set = (next: T) => {
603
+ const p = new URLSearchParams(params)
604
+ if (next === fallback) p.delete(key)
605
+ else p.set(key, next)
606
+ setParams(p, { replace: true })
607
+ }
608
+ return [value, set]
609
+ }
610
+
611
+ /** What an empty list says when its filters, not the cluster, emptied it. */
612
+ function noMatchText(noun: string, search: string, narrowed: boolean, read: KindRead): string | undefined {
613
+ if (read.state !== 'read' || read.items.length > 0) return undefined
614
+ if (narrowed) return `No ${noun} match these filters.`
615
+ return search.trim() ? `No ${noun} match this search.` : undefined
616
+ }
617
+
618
+ function NameSearch({ value, onChange, noun, id }: { value: string; onChange: (value: string) => void; noun: string; id: string }) {
619
+ return <SearchBox value={value} onChange={onChange} scope="resources" shortcutId={id} placeholder={`Search ${noun} by name`} className="w-64 max-w-full" />
620
+ }
621
+
622
+ function PoolSelect({
623
+ pools,
624
+ value,
625
+ onChange,
626
+ multiNamespace,
627
+ }: {
628
+ pools: { key: string; namespace: string; name: string }[]
629
+ value: string
630
+ onChange: (value: string) => void
631
+ multiNamespace: boolean
632
+ }) {
633
+ if (pools.length === 0) return null
634
+ return (
635
+ <select
636
+ aria-label="Filter by warm pool"
637
+ value={value}
638
+ onChange={(e) => onChange(e.target.value)}
639
+ className="h-8 rounded-lg border border-theme-border bg-theme-elevated px-2.5 text-xs text-theme-text-primary focus:outline-none focus:ring-2 focus:ring-accent"
640
+ >
641
+ <option value="">All warm pools</option>
642
+ {pools.map((p) => (
643
+ <option key={p.key} value={p.key}>
644
+ {multiNamespace ? `${p.namespace}/${p.name}` : p.name}
645
+ </option>
646
+ ))}
647
+ </select>
648
+ )
649
+ }
650
+
651
+ function listSubtitle(count: number, noun: [string, string], partial: boolean, namespaces: string[], items: any[], attentionCount: number | undefined, attentionPartial: boolean): string {
652
+ const prefix = partial ? '≥' : ''
653
+ const parts = [`${prefix}${count} ${count === 1 ? noun[0] : noun[1]}`]
654
+ if (attentionCount !== undefined && attentionCount > 0) parts.push(`${attentionPartial ? '≥' : ''}${attentionCount} need attention`)
655
+ if (namespaces.length > 0) parts.push(`in ${namespaces.join(', ')}`)
656
+ else {
657
+ const single = singleNamespaceOf(items)
658
+ if (single) parts.push(`in namespace ${single}`)
659
+ }
660
+ return parts.join(' · ')
661
+ }
662
+
663
+ const SANDBOX_SEGMENTS = ['all', 'attention', 'ready', 'settled'] as const
664
+ type SandboxSegment = (typeof SANDBOX_SEGMENTS)[number]
665
+
666
+ function isSandboxAttention(o: any, server?: ServerReadings): boolean {
667
+ if (server?.attentionObjects) return server.attentionObjects.sandboxes.has(rowKey(o))
668
+ const level = server?.tones.get(objectKey('Sandbox', ns(o), nm(o))) ?? getSandboxStatus(o).level
669
+ return level !== 'healthy' && level !== 'neutral'
670
+ }
671
+
672
+ export function SandboxesScreen({ data, namespaces, onClearNamespaces, onInspect, inspected, onCreate, server, attentionPending }: AgentSandboxScreenProps & { onCreate?: () => void; server?: ServerReadings }) {
673
+ const [params, setParams] = useSearchParams()
674
+ const [search, setSearch] = useNameSearch()
675
+ const [segment, setSegment] = useUrlParam<SandboxSegment>('segment', SANDBOX_SEGMENTS, 'all')
676
+ const pool = params.get('pool') ?? ''
677
+ const rawState = params.get('state')
678
+ const state = rawState === 'notReady' || rawState === 'expired' || rawState === 'recentlyExpired' ? rawState : ''
679
+ const clear = (key: string) => {
680
+ const p = new URLSearchParams(params)
681
+ p.delete(key)
682
+ setParams(p, { replace: true })
683
+ }
684
+ const setPool = (value: string) => {
685
+ const p = new URLSearchParams(params)
686
+ if (value) p.set('pool', value)
687
+ else p.delete('pool')
688
+ setParams(p, { replace: true })
689
+ }
690
+ const listFilters = useListFilters(SANDBOX_KIND)
691
+ const chips = [
692
+ ...(pool ? [{ label: `Warm pool: ${pool.slice(pool.indexOf('/') + 1)}`, onClear: () => clear('pool') }] : []),
693
+ ...(state === 'notReady' ? [{ label: 'Not ready', onClear: () => clear('state') }] : []),
694
+ ...(state === 'expired' || state === 'recentlyExpired' ? [{ label: state === 'expired' ? 'Expired' : 'Expired in the last 7 days', onClear: () => clear('state') }] : []),
695
+ ...listFilters.chips,
696
+ ]
697
+ const { apply } = listFilters
698
+ const baseItems = readItems(data.sandboxes)
699
+ const partial = isPartialRead(data.sandboxes)
700
+ const attentionPartial = partial || !!server?.sidebar?.sandboxes.lowerBound
701
+ const poolOptions = useMemo(() => {
702
+ const map = new Map<string, { key: string; namespace: string; name: string }>()
703
+ for (const p of readItems(data.warmPools)) {
704
+ const k = rowKey(p)
705
+ map.set(k, { key: k, namespace: ns(p), name: nm(p) })
706
+ }
707
+ for (const s of baseItems) {
708
+ const owner = sandboxController(s)
709
+ if (owner?.kind === 'SandboxWarmPool') {
710
+ const k = `${owner.namespace}/${owner.name}`
711
+ if (!map.has(k)) map.set(k, { key: k, namespace: owner.namespace, name: owner.name })
712
+ }
713
+ }
714
+ return [...map.values()].sort((a, b) => a.key.localeCompare(b.key))
715
+ }, [data.warmPools, baseItems])
716
+ const multiPoolNs = new Set(poolOptions.map((p) => p.namespace)).size > 1
717
+
718
+ const counts = useMemo(() => {
719
+ let attention = 0
720
+ let ready = 0
721
+ let settled = 0
722
+ for (const o of baseItems) {
723
+ const level = server?.tones.get(objectKey('Sandbox', ns(o), nm(o))) ?? getSandboxStatus(o).level
724
+ if (isSandboxAttention(o, server)) attention++
725
+ else if (level === 'healthy') ready++
726
+ else if (level === 'neutral') settled++
727
+ }
728
+ return { all: baseItems.length, attention, ready, settled }
729
+ }, [baseItems, server])
730
+
731
+ const bySegment = useMemo(() => {
732
+ const base = filterSandboxes(data.sandboxes, pool, state)
733
+ if (segment === 'all') return base
734
+ return filterItems(base, (o) => {
735
+ const level = server?.tones.get(objectKey('Sandbox', ns(o), nm(o))) ?? getSandboxStatus(o).level
736
+ if (segment === 'attention') return isSandboxAttention(o, server)
737
+ if (isSandboxAttention(o, server)) return false
738
+ if (segment === 'ready') return level === 'healthy'
739
+ return level === 'neutral'
740
+ })
741
+ }, [data.sandboxes, pool, state, segment, server])
742
+
743
+ const sandboxes = useMemo(() => filterByName(apply(bySegment), search), [bySegment, search, apply])
744
+ const narrowed = !!pool || !!state || segment !== 'all' || listFilters.narrows
745
+ const empty = noMatchText('Sandboxes', search, narrowed, sandboxes)
746
+ const showSegmentCounts = !(search || pool || state || listFilters.narrows)
747
+ const attentionCount = attentionPending ? undefined : counts.attention
748
+ const subtitle = data.sandboxes.state === 'read' ? listSubtitle(counts.all, ['sandbox', 'sandboxes'], partial, namespaces, baseItems, attentionCount, attentionPartial) : undefined
749
+
750
+ return (
751
+ <div className="flex min-h-0 flex-1 flex-col">
752
+ <AgentSandboxHeader title="Sandboxes" subtitle={subtitle} namespaces={namespaces} onClearNamespaces={onClearNamespaces} chips={chips} actions={<CreateButton onCreate={onCreate} label={SANDBOX_KIND.kind} />} />
753
+ <ScreenBody>
754
+ <div className="flex flex-wrap items-center gap-2">
755
+ <Segments
756
+ label="Filter sandboxes by state"
757
+ value={segment}
758
+ onChange={setSegment}
759
+ options={[
760
+ { id: 'all', label: 'All', count: showSegmentCounts ? countBadge(counts.all, partial) : undefined },
761
+ { id: 'attention', label: 'Needs attention', count: showSegmentCounts && attentionCount !== undefined ? countBadge(attentionCount, attentionPartial) : undefined },
762
+ { id: 'ready', label: 'Ready', count: showSegmentCounts ? countBadge(counts.ready, partial) : undefined },
763
+ { id: 'settled', label: 'Settled', count: showSegmentCounts ? countBadge(counts.settled, partial) : undefined },
764
+ ]}
765
+ />
766
+ <PoolSelect pools={poolOptions} value={pool} onChange={setPool} multiNamespace={multiPoolNs} />
767
+ <div className="ml-auto">
768
+ <NameSearch value={search} onChange={setSearch} noun="sandboxes" id="agent-sandbox-sandboxes-search" />
769
+ </div>
770
+ </div>
771
+ <AgentSandboxCoverageNotice data={data} kinds={['sandboxes', 'claims']} />
772
+ {segment === 'attention' && attentionPending ? <PaneLoader label="Loading Agent Sandbox…" className="h-32" /> : (
773
+ <SandboxesTable read={sandboxes} claims={data.claims} onInspect={onInspect} inspected={inspected} server={server} empty={empty} />
774
+ )}
775
+ </ScreenBody>
776
+ </div>
777
+ )
778
+ }
779
+
780
+ const CLAIM_SEGMENTS = ['all', 'attention', 'bound', 'expired'] as const
781
+ type ClaimSegment = (typeof CLAIM_SEGMENTS)[number]
782
+
783
+ function classifyClaim(o: any): 'attention' | 'bound' | 'expired' {
784
+ const status = getSandboxClaimStatus(o)
785
+ if (status.text === 'Expired') return 'expired'
786
+ return claimSandboxName(o) ? 'bound' : 'attention'
787
+ }
788
+
789
+ function isClaimAttention(o: any, server?: ServerReadings): boolean {
790
+ if (server?.attentionObjects) return server.attentionObjects.claims.has(rowKey(o))
791
+ const level = server?.tones.get(objectKey('SandboxClaim', ns(o), nm(o))) ?? getSandboxClaimStatus(o).level
792
+ return level === 'unhealthy' || level === 'alert' || level === 'degraded'
793
+ }
794
+
795
+ export function ClaimsScreen({ data, namespaces, onClearNamespaces, onInspect, inspected, onCreate, server, attentionPending }: AgentSandboxScreenProps & { onCreate?: () => void; server?: ServerReadings }) {
796
+ const [params, setParams] = useSearchParams()
797
+ const [search, setSearch] = useNameSearch()
798
+ const [segment, setSegment] = useUrlParam<ClaimSegment>('segment', CLAIM_SEGMENTS, 'all')
799
+ const recent = params.get('state') === 'recentlyExpired'
800
+ const pool = params.get('pool') ?? ''
801
+ const setPool = (value: string) => {
802
+ const p = new URLSearchParams(params)
803
+ if (value) p.set('pool', value)
804
+ else p.delete('pool')
805
+ setParams(p, { replace: true })
806
+ }
807
+ const { apply, narrows, chips: listChips } = useListFilters(SANDBOX_CLAIM_KIND)
808
+ const chips = [
809
+ ...(pool ? [{ label: `Warm pool: ${pool.slice(pool.indexOf('/') + 1)}`, onClear: () => setPool('') }] : []),
810
+ ...(recent ? [{ label: 'Expired in the last 7 days', onClear: () => {
811
+ const next = new URLSearchParams(params)
812
+ next.delete('state')
813
+ setParams(next, { replace: true })
814
+ } }] : []),
815
+ ...listChips,
816
+ ]
817
+ const baseItems = readItems(data.claims)
818
+ const partial = isPartialRead(data.claims)
819
+ const attentionPartial = partial || !!server?.sidebar?.claims.lowerBound
820
+ const poolOptions = useMemo(() => {
821
+ const map = new Map<string, { key: string; namespace: string; name: string }>()
822
+ for (const p of readItems(data.warmPools)) {
823
+ const k = rowKey(p)
824
+ map.set(k, { key: k, namespace: ns(p), name: nm(p) })
825
+ }
826
+ for (const c of baseItems) {
827
+ const ref = getSandboxClaimWarmPool(c)
828
+ if (ref && ref !== '-') {
829
+ const k = `${ns(c)}/${ref}`
830
+ if (!map.has(k)) map.set(k, { key: k, namespace: ns(c), name: ref })
831
+ }
832
+ }
833
+ return [...map.values()].sort((a, b) => a.key.localeCompare(b.key))
834
+ }, [data.warmPools, baseItems])
835
+ const multiPoolNs = new Set(poolOptions.map((p) => p.namespace)).size > 1
836
+
837
+ const counts = useMemo(() => {
838
+ let attention = 0
839
+ let bound = 0
840
+ let expired = 0
841
+ for (const o of baseItems) {
842
+ const bucket = classifyClaim(o)
843
+ if (isClaimAttention(o, server)) attention++
844
+ if (bucket === 'bound') bound++
845
+ if (bucket === 'expired') expired++
846
+ }
847
+ return { all: baseItems.length, attention, bound, expired }
848
+ }, [baseItems, server])
849
+
850
+ const narrowedRead = useMemo(() => {
851
+ let next = data.claims
852
+ if (pool) {
853
+ next = filterItems(next, (c) => `${ns(c)}/${getSandboxClaimWarmPool(c)}` === pool)
854
+ }
855
+ if (segment !== 'all') {
856
+ next = filterItems(next, (c) => segment === 'attention' ? isClaimAttention(c, server) : classifyClaim(c) === segment)
857
+ }
858
+ if (recent) next = filterItems(next, (c) => getSandboxClaimStatus(c).text === 'Expired' && recentlyExpired(c))
859
+ return next
860
+ }, [data.claims, pool, segment, server, recent])
861
+
862
+ const claims = useMemo(() => filterByName(apply(narrowedRead), search), [narrowedRead, search, apply])
863
+ const empty = noMatchText('SandboxClaims', search, narrows || !!pool || recent || segment !== 'all', claims)
864
+ const showSegmentCounts = !(search || pool || recent || narrows)
865
+ const attentionCount = attentionPending ? undefined : counts.attention
866
+ const subtitle = data.claims.state === 'read' ? listSubtitle(counts.all, ['claim', 'claims'], partial, namespaces, baseItems, attentionCount, attentionPartial) : undefined
867
+
868
+ return (
869
+ <div className="flex min-h-0 flex-1 flex-col">
870
+ <AgentSandboxHeader title="Claims" subtitle={subtitle} namespaces={namespaces} onClearNamespaces={onClearNamespaces} chips={chips} actions={<CreateButton onCreate={onCreate} label={SANDBOX_CLAIM_KIND.kind} />} />
871
+ <ScreenBody>
872
+ <div className="flex flex-wrap items-center gap-2">
873
+ <Segments
874
+ label="Filter claims by state"
875
+ value={segment}
876
+ onChange={setSegment}
877
+ options={[
878
+ { id: 'all', label: 'All', count: showSegmentCounts ? countBadge(counts.all, partial) : undefined },
879
+ { id: 'attention', label: 'Needs attention', count: showSegmentCounts && attentionCount !== undefined ? countBadge(attentionCount, attentionPartial) : undefined },
880
+ { id: 'bound', label: 'Bound', count: showSegmentCounts ? countBadge(counts.bound, partial) : undefined },
881
+ { id: 'expired', label: 'Expired', count: showSegmentCounts ? countBadge(counts.expired, partial) : undefined },
882
+ ]}
883
+ />
884
+ <PoolSelect pools={poolOptions} value={pool} onChange={setPool} multiNamespace={multiPoolNs} />
885
+ <div className="ml-auto">
886
+ <NameSearch value={search} onChange={setSearch} noun="claims" id="agent-sandbox-claims-search" />
887
+ </div>
888
+ </div>
889
+ <AgentSandboxCoverageNotice data={data} kinds={['claims', 'warmPools']} />
890
+ {segment === 'attention' && attentionPending ? <PaneLoader label="Loading Agent Sandbox…" className="h-32" /> : (
891
+ <ClaimsTable read={claims} warmPools={data.warmPools} onInspect={onInspect} inspected={inspected} server={server} empty={empty} />
892
+ )}
893
+ </ScreenBody>
894
+ </div>
895
+ )
896
+ }
897
+
898
+ const WARM_POOL_SEGMENTS = ['all', 'attention', 'ready'] as const
899
+ type WarmPoolSegment = (typeof WARM_POOL_SEGMENTS)[number]
900
+
901
+ function isWarmPoolAttention(o: any, server?: ServerReadings): boolean {
902
+ if (server?.attentionObjects) return server.attentionObjects.warmPools.has(rowKey(o))
903
+ const key = objectKey('SandboxWarmPool', ns(o), nm(o))
904
+ if (server?.rows.has(key)) return true
905
+ const level = server?.tones.get(key) ?? getSandboxWarmPoolStatus(o).level
906
+ return level !== 'healthy' && level !== 'neutral'
907
+ }
908
+
909
+ export function WarmPoolsScreen({ data, namespaces, onClearNamespaces, onInspect, inspected, onCreate, server, attentionPending }: AgentSandboxScreenProps & { onCreate?: () => void; server?: ServerReadings }) {
910
+ const [search, setSearch] = useNameSearch()
911
+ const [segment, setSegment] = useUrlParam<WarmPoolSegment>('segment', WARM_POOL_SEGMENTS, 'all')
912
+ const { apply, narrows, chips } = useListFilters(SANDBOX_WARM_POOL_KIND)
913
+ const baseItems = readItems(data.warmPools)
914
+ const partial = isPartialRead(data.warmPools)
915
+ const attentionPartial = partial || !!server?.sidebar?.warmPools.lowerBound
916
+
917
+ const counts = useMemo(() => {
918
+ let attention = 0
919
+ let ready = 0
920
+ for (const o of baseItems) {
921
+ if (isWarmPoolAttention(o, server)) attention++
922
+ else if (getSandboxWarmPoolStatus(o).level === 'healthy') ready++
923
+ }
924
+ return { all: baseItems.length, attention, ready }
925
+ }, [baseItems, server])
926
+
927
+ const bySegment = useMemo(() => {
928
+ if (segment === 'all') return data.warmPools
929
+ return filterItems(data.warmPools, (o) =>
930
+ segment === 'attention' ? isWarmPoolAttention(o, server) : !isWarmPoolAttention(o, server) && getSandboxWarmPoolStatus(o).level === 'healthy',
931
+ )
932
+ }, [data.warmPools, segment, server])
933
+
934
+ const pools = useMemo(() => filterByName(apply(bySegment), search), [bySegment, search, apply])
935
+ const empty = noMatchText('SandboxWarmPools', search, narrows || segment !== 'all', pools)
936
+ const showSegmentCounts = !(search || narrows)
937
+ const attentionCount = attentionPending ? undefined : counts.attention
938
+ const subtitle = data.warmPools.state === 'read' ? listSubtitle(counts.all, ['warm pool', 'warm pools'], partial, namespaces, baseItems, attentionCount, attentionPartial) : undefined
939
+
940
+ return (
941
+ <div className="flex min-h-0 flex-1 flex-col">
942
+ <AgentSandboxHeader title="Warm pools" subtitle={subtitle} namespaces={namespaces} onClearNamespaces={onClearNamespaces} chips={chips} actions={<CreateButton onCreate={onCreate} label={SANDBOX_WARM_POOL_KIND.kind} />} />
943
+ <ScreenBody>
944
+ <div className="flex flex-wrap items-center gap-2">
945
+ <Segments
946
+ label="Filter warm pools by state"
947
+ value={segment}
948
+ onChange={setSegment}
949
+ options={[
950
+ { id: 'all', label: 'All', count: showSegmentCounts ? countBadge(counts.all, partial) : undefined },
951
+ { id: 'attention', label: 'Needs attention', count: showSegmentCounts && attentionCount !== undefined ? countBadge(attentionCount, attentionPartial) : undefined },
952
+ { id: 'ready', label: 'Ready', count: showSegmentCounts ? countBadge(counts.ready, partial) : undefined },
953
+ ]}
954
+ />
955
+ <div className="ml-auto">
956
+ <NameSearch value={search} onChange={setSearch} noun="warm pools" id="agent-sandbox-warm-pools-search" />
957
+ </div>
958
+ </div>
959
+ <AgentSandboxCoverageNotice data={data} kinds={['warmPools', 'claims']} />
960
+ {segment === 'attention' && attentionPending ? <PaneLoader label="Loading Agent Sandbox…" className="h-32" /> : (
961
+ <WarmPoolsTable read={pools} claims={readItems(data.claims)} claimsRead={data.claims} onInspect={onInspect} inspected={inspected} server={server} empty={empty} />
962
+ )}
963
+ </ScreenBody>
964
+ </div>
965
+ )
966
+ }