@skyhook-io/radar-app 1.22.2 → 1.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/package.json +8 -8
  2. package/src/App.tsx +49 -13
  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 +151 -27
  9. package/src/api/client.updateResource.secretExpiry.test.tsx +47 -0
  10. package/src/api/cloudInstallDiscover.test.tsx +76 -0
  11. package/src/api/diagnose.ts +4 -0
  12. package/src/api/kagent.test.ts +82 -0
  13. package/src/api/kagent.ts +230 -0
  14. package/src/api/poll.ts +78 -0
  15. package/src/api/prometheusCharts.ts +5 -0
  16. package/src/api/radarFeatures.test.ts +9 -0
  17. package/src/api/radarFeatures.ts +16 -0
  18. package/src/api/substrateWorkspace.test.ts +72 -0
  19. package/src/api/substrateWorkspace.ts +1394 -0
  20. package/src/api/vulnerabilities.ts +207 -9
  21. package/src/api/workloadSource.test.tsx +315 -0
  22. package/src/api/workloadSource.ts +128 -12
  23. package/src/components/CloudConnectFlow.tsx +46 -7
  24. package/src/components/CloudFunnelButton.test.tsx +193 -7
  25. package/src/components/CloudFunnelButton.tsx +128 -32
  26. package/src/components/SelfManagedStart.tsx +12 -2
  27. package/src/components/agentsandbox/AgentSandboxKindLists.tsx +41 -0
  28. package/src/components/agentsandbox/AgentSandboxLists.test.tsx +410 -0
  29. package/src/components/agentsandbox/AgentSandboxOverview.test.tsx +333 -0
  30. package/src/components/agentsandbox/AgentSandboxOverview.tsx +555 -0
  31. package/src/components/agentsandbox/AgentSandboxSidebar.test.tsx +97 -0
  32. package/src/components/agentsandbox/AgentSandboxSummary.test.tsx +439 -0
  33. package/src/components/agentsandbox/AgentSandboxSummary.tsx +956 -0
  34. package/src/components/agentsandbox/AgentSandboxTables.tsx +966 -0
  35. package/src/components/agentsandbox/AgentSandboxView.tsx +34 -0
  36. package/src/components/agentsandbox/agentsandbox.fixtures.ts +135 -0
  37. package/src/components/agentsandbox/data.ts +135 -0
  38. package/src/components/agentsandbox/host.test.ts +27 -0
  39. package/src/components/agentsandbox/host.tsx +85 -0
  40. package/src/components/agentsandbox/labels.test.ts +42 -0
  41. package/src/components/agentsandbox/labels.ts +146 -0
  42. package/src/components/agentsandbox/listFilters.ts +85 -0
  43. package/src/components/agentsandbox/lists.ts +52 -0
  44. package/src/components/agentsandbox/routes.ts +23 -0
  45. package/src/components/agentsandbox/shared.tsx +321 -0
  46. package/src/components/agentsandbox/useAgentSandboxSidebarWorkspace.ts +69 -0
  47. package/src/components/agentsandbox/workspace.fixtures.ts +125 -0
  48. package/src/components/agentsandbox/workspace.tsx +258 -0
  49. package/src/components/agentsandbox/workspaceRoute.ts +18 -0
  50. package/src/components/applications/ApplicationsView.openResource.test.tsx +248 -3
  51. package/src/components/applications/ApplicationsView.tsx +156 -3
  52. package/src/components/audit/VulnerabilitiesColumns.test.tsx +487 -0
  53. package/src/components/audit/VulnerabilitiesRisk.test.tsx +318 -0
  54. package/src/components/audit/VulnerabilitiesView.test.tsx +458 -13
  55. package/src/components/audit/VulnerabilitiesView.tsx +639 -199
  56. package/src/components/cloudHints/AgentSetupCloudRow.tsx +28 -0
  57. package/src/components/cloudHints/CloudHintLink.tsx +29 -0
  58. package/src/components/cloudHints/SharedInstallAiLine.tsx +36 -0
  59. package/src/components/cloudHints/cloudHints.test.ts +126 -0
  60. package/src/components/cloudHints/cloudHints.ts +131 -0
  61. package/src/components/cloudHints/cloudHintsGate.test.tsx +70 -0
  62. package/src/components/cloudHints/cloudLinks.test.ts +52 -0
  63. package/src/components/cloudHints/cloudLinks.ts +31 -0
  64. package/src/components/cloudHints/hintStorage.ts +28 -0
  65. package/src/components/cnpg/CNPGView.tsx +4 -7
  66. package/src/components/diagnose/AgentSetupNotice.tsx +5 -0
  67. package/src/components/diagnose/DiagnoseContext.tsx +7 -0
  68. package/src/components/diagnose/DiagnoseSurface.escape.test.tsx +215 -0
  69. package/src/components/diagnose/DiagnoseSurface.tsx +57 -1
  70. package/src/components/gitops/RemoteDestinationCloudHint.tsx +6 -14
  71. package/src/components/helm/HelmDrawerRouting.test.tsx +34 -1
  72. package/src/components/helm/HelmReleaseDrawer.tsx +6 -4
  73. package/src/components/helm/HelmView.tsx +4 -3
  74. package/src/components/helm/ObservedHelmNotice.tsx +39 -17
  75. package/src/components/helm/ObservedHelmRelease.test.tsx +62 -3
  76. package/src/components/helm/ObservedHelmReleaseDrawer.test.tsx +18 -0
  77. package/src/components/helm/ObservedHelmReleaseDrawer.tsx +4 -2
  78. package/src/components/home/HomeAgentBlock.tsx +2 -0
  79. package/src/components/home/HomeView.tsx +3 -3
  80. package/src/components/home/MCPSetupDialog.test.tsx +9 -0
  81. package/src/components/home/MCPSetupDialog.tsx +6 -2
  82. package/src/components/home/McpCloudLine.test.tsx +162 -0
  83. package/src/components/home/McpCloudLine.tsx +95 -0
  84. package/src/components/home/ProblemsPanel.investigate.test.tsx +2 -2
  85. package/src/components/home/mcpToolCatalog.test.ts +10 -0
  86. package/src/components/home/mcpToolCatalog.ts +4 -4
  87. package/src/components/issues/ClusterSchedulingBlockerRow.tsx +35 -0
  88. package/src/components/issues/IssuesPane.render.test.tsx +36 -1
  89. package/src/components/issues/IssuesPane.tsx +181 -23
  90. package/src/components/issues/SinceLastVisitRow.render.test.tsx +302 -0
  91. package/src/components/issues/SinceLastVisitRow.tsx +71 -0
  92. package/src/components/issues/sinceLastVisit.test.ts +266 -0
  93. package/src/components/issues/sinceLastVisit.ts +439 -0
  94. package/src/components/issues/uncheckedSources.test.ts +8 -0
  95. package/src/components/issues/uncheckedSources.ts +3 -0
  96. package/src/components/kagent/KagentAgentRenderer.test.ts +32 -0
  97. package/src/components/kagent/KagentAgentRenderer.tsx +87 -0
  98. package/src/components/kagent/KagentAgentSessions.test.tsx +166 -0
  99. package/src/components/kagent/KagentAgentSessions.tsx +124 -0
  100. package/src/components/kagent/KagentDetailPage.tsx +106 -0
  101. package/src/components/kagent/KagentLists.tsx +412 -0
  102. package/src/components/kagent/KagentOverview.tsx +234 -0
  103. package/src/components/kagent/KagentPages.tsx +690 -0
  104. package/src/components/kagent/KagentRuntimeTabs.test.tsx +219 -0
  105. package/src/components/kagent/KagentRuntimeTabs.tsx +283 -0
  106. package/src/components/kagent/KagentSidebar.test.tsx +112 -0
  107. package/src/components/kagent/KagentView.tsx +109 -0
  108. package/src/components/kagent/KagentWorkspace.test.tsx +876 -0
  109. package/src/components/kagent/host.tsx +144 -0
  110. package/src/components/kagent/routes.ts +31 -0
  111. package/src/components/kagent/shared.tsx +336 -0
  112. package/src/components/kagent/useKagentRuntime.test.tsx +77 -0
  113. package/src/components/kagent/useKagentSidebarWorkspace.ts +67 -0
  114. package/src/components/kagent/workspace.fixtures.ts +108 -0
  115. package/src/components/kagent/workspaceRoute.ts +18 -0
  116. package/src/components/nudges/activeNudges.test.ts +39 -0
  117. package/src/components/nudges/activeNudges.ts +76 -0
  118. package/src/components/poll/OssPoll.tsx +871 -0
  119. package/src/components/poll/mount.test.ts +12 -0
  120. package/src/components/poll/pollCloud.test.ts +23 -0
  121. package/src/components/poll/pollCloud.ts +6 -0
  122. package/src/components/poll/pollDefinition.ts +93 -0
  123. package/src/components/poll/pollFlow.test.ts +140 -0
  124. package/src/components/poll/pollFlow.ts +137 -0
  125. package/src/components/poll/pollSender.test.ts +137 -0
  126. package/src/components/poll/pollSender.ts +76 -0
  127. package/src/components/poll/pollStorage.test.ts +53 -0
  128. package/src/components/poll/pollStorage.ts +77 -0
  129. package/src/components/poll/round.json +350 -0
  130. package/src/components/product-hunt/ProductHuntNotice.tsx +2 -0
  131. package/src/components/resource/MetricsNotConnected.test.tsx +28 -0
  132. package/src/components/resource/MetricsNotConnected.tsx +10 -7
  133. package/src/components/resource/PrometheusCharts.tsx +10 -1
  134. package/src/components/resource/PrometheusChartsGrid.render.test.tsx +9 -0
  135. package/src/components/resource/PrometheusChartsGrid.tsx +3 -3
  136. package/src/components/resource/SubstrateHealthCharts.test.tsx +13 -1
  137. package/src/components/resource/SubstrateHealthCharts.tsx +9 -15
  138. package/src/components/resources/ImageFilesystemModal.test.tsx +21 -1
  139. package/src/components/resources/ImageFilesystemModal.tsx +42 -3
  140. package/src/components/resources/ResourceDetailDrawer.tsx +1 -0
  141. package/src/components/resources/ResourcesView.tsx +24 -11
  142. package/src/components/resources/renderers/PodRenderer.tsx +8 -2
  143. package/src/components/settings/LocalIntegrationStatus.test.tsx +1 -0
  144. package/src/components/settings/LocalIntegrationStatus.tsx +3 -2
  145. package/src/components/settings/SettingsDialog.tsx +84 -16
  146. package/src/components/settings/SubstrateSettings.lifecycle.test.tsx +210 -0
  147. package/src/components/settings/SubstrateSettings.test.tsx +131 -0
  148. package/src/components/settings/SubstrateSettings.tsx +544 -0
  149. package/src/components/settings/settings-state.test.ts +21 -3
  150. package/src/components/settings/settings-state.ts +13 -3
  151. package/src/components/share/ShareLinkButton.test.tsx +360 -0
  152. package/src/components/share/ShareLinkButton.tsx +391 -0
  153. package/src/components/share/openShareInCloud.test.ts +29 -0
  154. package/src/components/share/openShareInCloud.ts +10 -0
  155. package/src/components/share/shareLink.test.ts +129 -0
  156. package/src/components/share/shareLink.ts +175 -0
  157. package/src/components/substrate/SubstrateActorDrawer.tsx +87 -0
  158. package/src/components/substrate/SubstrateActorOverview.tsx +489 -0
  159. package/src/components/substrate/SubstrateActorPage.tsx +384 -0
  160. package/src/components/substrate/SubstrateActors.test.tsx +1094 -0
  161. package/src/components/substrate/SubstrateActors.tsx +612 -0
  162. package/src/components/substrate/SubstrateAttentionList.tsx +441 -0
  163. package/src/components/substrate/SubstrateConnect.tsx +88 -0
  164. package/src/components/substrate/SubstrateOverview.test.tsx +396 -0
  165. package/src/components/substrate/SubstrateOverview.tsx +575 -0
  166. package/src/components/substrate/SubstratePages.test.tsx +478 -0
  167. package/src/components/substrate/SubstratePool.test.tsx +462 -0
  168. package/src/components/substrate/SubstratePoolPage.tsx +95 -0
  169. package/src/components/substrate/SubstratePoolSummary.tsx +485 -0
  170. package/src/components/substrate/SubstrateSidebar.test.tsx +101 -0
  171. package/src/components/substrate/SubstrateStateBar.tsx +63 -0
  172. package/src/components/substrate/SubstrateTemplates.tsx +376 -0
  173. package/src/components/substrate/SubstrateView.tsx +173 -0
  174. package/src/components/substrate/SubstrateWorkerPodContext.tsx +73 -0
  175. package/src/components/substrate/SubstrateWorkers.tsx +389 -0
  176. package/src/components/substrate/attention.ts +81 -0
  177. package/src/components/substrate/contextPin.tsx +69 -0
  178. package/src/components/substrate/host.tsx +83 -0
  179. package/src/components/substrate/kubectlTarget.test.tsx +77 -0
  180. package/src/components/substrate/readings.test.ts +484 -0
  181. package/src/components/substrate/readings.ts +997 -0
  182. package/src/components/substrate/routes.ts +103 -0
  183. package/src/components/substrate/shared.tsx +426 -0
  184. package/src/components/substrate/substrate.fixtures.ts +325 -0
  185. package/src/components/substrate/useSubstrateSidebarWorkspace.ts +87 -0
  186. package/src/components/substrate/workspaceRoute.ts +23 -0
  187. package/src/components/traffic/TrafficConnectionsTable.test.tsx +9 -0
  188. package/src/components/traffic/TrafficConnectionsTable.tsx +4 -2
  189. package/src/components/traffic/TrafficFilterSidebar.tsx +19 -14
  190. package/src/components/traffic/TrafficFlowList.test.tsx +63 -0
  191. package/src/components/traffic/TrafficFlowList.tsx +9 -5
  192. package/src/components/traffic/TrafficGraph.test.tsx +26 -0
  193. package/src/components/traffic/TrafficGraph.tsx +17 -14
  194. package/src/components/traffic/TrafficGraphTooLarge.tsx +2 -0
  195. package/src/components/traffic/TrafficGraphUnavailable.tsx +3 -1
  196. package/src/components/traffic/TrafficView.tsx +26 -56
  197. package/src/components/traffic/trafficFilters.test.ts +61 -1
  198. package/src/components/traffic/trafficFilters.ts +68 -8
  199. package/src/components/ui/UpdateNotification.tsx +2 -0
  200. package/src/components/usage-data/UsageDataPrompt.tsx +2 -0
  201. package/src/components/velero/VeleroOverview.tsx +2 -2
  202. package/src/components/velero/VeleroView.tsx +3 -6
  203. package/src/components/vulnerabilities/columns.tsx +132 -0
  204. package/src/components/vulnerabilities/filters.tsx +317 -0
  205. package/src/components/vulnerabilities/owner.test.ts +54 -0
  206. package/src/components/vulnerabilities/owner.tsx +163 -0
  207. package/src/components/vulnerabilities/parts.test.ts +126 -12
  208. package/src/components/vulnerabilities/parts.tsx +612 -52
  209. package/src/components/vulnerabilities/traffic.test.tsx +65 -0
  210. package/src/components/vulnerabilities/traffic.tsx +40 -0
  211. package/src/components/whats-new/WhatsNew.tsx +2 -0
  212. package/src/components/whats-new/releaseNotes.ts +75 -1
  213. package/src/components/workload/WorkloadView.substrateVersion.test.tsx +88 -0
  214. package/src/components/workload/WorkloadView.tsx +52 -13
  215. package/src/components/workspace/layout.tsx +13 -7
  216. package/src/components/workspace/sidebar.test.ts +48 -0
  217. package/src/components/workspace/sidebar.ts +73 -3
  218. package/src/components/workspace/table.ts +2 -1
  219. package/src/contexts/RegistryAccessMode.test.tsx +51 -0
  220. package/src/contexts/RegistryAccessMode.tsx +25 -0
  221. package/src/integrations/resourceHost.ts +12 -6
  222. package/src/integrations/resourceHosts.test.tsx +27 -1
  223. package/src/integrations/resourceHosts.tsx +15 -7
  224. package/src/integrations/sidebarWorkspaces.test.tsx +63 -0
  225. package/src/integrations/sidebarWorkspaces.ts +41 -0
  226. package/src/integrations/workspaceRoute.ts +1 -1
  227. package/src/integrations/workspaceRoutes.ts +7 -1
  228. package/src/integrations/workspaceScreens.tsx +6 -0
@@ -0,0 +1,376 @@
1
+ import { useState } from 'react'
2
+ import { useSearchParams } from 'react-router-dom'
3
+ import { Bot, FileCode, LayoutDashboard, RefreshCw } from 'lucide-react'
4
+ import { Badge, CertaintyGlyph, DetailShell, DimensionValue, FactGrid, FactRow, FoldSection, Input, PaneLoader, SelectMenu, Tooltip, WorkspaceCard, WorkspaceProblemCallout, type WorkspaceProblem } from '@skyhook-io/k8s-ui'
5
+ import {
6
+ substrateErrorCode,
7
+ useSubstrateTemplate,
8
+ useSubstrateWorkspace,
9
+ useSubstrateTemplates,
10
+ type SubstrateRef,
11
+ type SubstrateStatus,
12
+ type SubstrateTemplateRow,
13
+ type SubstrateTemplateSpec,
14
+ type SubstrateWorkspace,
15
+ } from '../../api/substrateWorkspace'
16
+ import { Notice, RefreshFailedNotice, ScreenBody, ScreenEmptyState, SectionTable, Segments, Sub, type TableColumn } from '../workspace/layout'
17
+ import { INCOMPLETE_COVERAGE_STATES } from '../workspace/coverage'
18
+ import { useConnection } from '../../context/ConnectionContext'
19
+ import { NotInContext, useContextPin } from './contextPin'
20
+ import { useWorkspaceNavigate } from '../workspace/useWorkspaceNavigate'
21
+ import { type OpenSubject } from './SubstrateAttentionList'
22
+ import { SubstrateConnectNotice, SubstrateTierBanner } from './SubstrateConnect'
23
+ import { agentText, attentionTone, kagentGoldenStep, kagentTemplateText, memoryRebuildStep, templateYamlCommand, bytesText, coverageInPart, coverageReason, cpuText, definitiveFailure, withoutReasonCode, fidelityLabel, goldenReading, splitReading, templateFilterValue, tierReading } from './readings'
24
+ import { SUBSTRATE_PATH, SUBSTRATE_SCREENS, substrateActorsPath, substrateTemplatePath } from './routes'
25
+ import { CommandChip, Name, PoolMatchLinks, SUBSTRATE_TERMS, SUBSTRATE_WIDE, SubstrateCoverageNotice, SubstrateHeader, SubstrateSourceLine, Term, Unread, When, WholeNames } from './shared'
26
+ import { useMediaQuery } from '../../hooks/useMediaQuery'
27
+
28
+ /** `named` says what the chip is about, for a place where it stands alone (a page header), not under a Golden snapshot column. */
29
+ export function GoldenBadge({ template, named }: { template: Pick<SubstrateTemplateRow, 'golden' | 'matchingPools' | 'matchingPoolsComplete'>; named?: boolean }) {
30
+ const g = goldenReading(template)
31
+ const severity = template.matchingPoolsComplete && template.matchingPools?.length === 0 ? 'alert' : g.severity
32
+ const label = named && !g.label.startsWith('Can’t') ? `Golden snapshot ${g.label.toLowerCase()}` : g.label
33
+ // Standing alone, the chip is where a page first names the term: its tooltip defines it first.
34
+ const tip = named ? `Golden snapshot: ${SUBSTRATE_TERMS.golden.charAt(0).toLowerCase()}${SUBSTRATE_TERMS.golden.slice(1)} ${g.meaning}` : g.meaning
35
+ return <Tooltip content={tip}><span><Badge severity={severity} size="sm" className="whitespace-normal text-left">{label}</Badge></span></Tooltip>
36
+ }
37
+
38
+ function PoolsCell({ t }: { t: SubstrateTemplateRow }) {
39
+ if (t.matchingPools === null) return <Unread title="Radar could not read enough of the pools to determine matches.">Unknown</Unread>
40
+ return <Tooltip content={t.matchingPools.map((p) => `${p.namespace}/${p.name}`).join(', ') || 'No pool labels match'}>
41
+ <span>{t.matchingPoolsComplete ? '' : '≥'}{t.matchingPools.length} {t.matchingPools.length === 1 ? 'pool' : 'pools'}</span>
42
+ </Tooltip>
43
+ }
44
+
45
+ function resourcesText(t: Pick<SubstrateTemplateRow, 'cpuMillicores' | 'memoryBytes'>): string {
46
+ return `${t.cpuMillicores !== undefined ? `${cpuText(t.cpuMillicores)} CPU` : 'CPU unreported'} · ${t.memoryBytes !== undefined ? bytesText(t.memoryBytes) : 'memory unreported'}`
47
+ }
48
+
49
+ function templateRank(t: SubstrateTemplateRow): number {
50
+ if (t.matchingPoolsComplete && t.matchingPools?.length === 0) return 0
51
+ if (t.golden.state === 'failed') return 1
52
+ if (t.attentionCount) return 2
53
+ return 3
54
+ }
55
+
56
+ export function SubstrateTemplatesScreen({ workspace, status }: { workspace?: SubstrateWorkspace; status?: SubstrateStatus }) {
57
+ const navigate = useWorkspaceNavigate()
58
+ const { connection } = useConnection()
59
+ const [search, setSearch] = useState('')
60
+ const [atespace, setAtespace] = useState('')
61
+ const [filter, setFilter] = useState<'all' | 'attention' | 'ready'>('all')
62
+ const tier = workspace?.apiTier
63
+ const connected = tier?.state === 'connected'
64
+ const query = useSubstrateTemplates(connected)
65
+ const data = query.data
66
+ const wide = useMediaQuery(SUBSTRATE_WIDE)
67
+ const actorsPartial = coverageInPart(data?.coverage.actors) || coverageInPart(data?.coverage.workers)
68
+ const open = (t: SubstrateRef) => navigate(substrateTemplatePath(t, connection.context || undefined))
69
+ const atespaces = [...new Set(data?.templates.map((t) => t.atespace))].sort()
70
+ const scoped = (data?.templates ?? []).filter((t) => (!atespace || t.atespace === atespace) && templateFilterValue(t).toLowerCase().includes(search.trim().toLowerCase()))
71
+ const needsAttention = (t: SubstrateTemplateRow) => templateRank(t) < 3
72
+ const ready = (t: SubstrateTemplateRow) => t.golden.state === 'ready' && !needsAttention(t)
73
+ const partial = coverageInPart(data?.coverage.templates)
74
+ const verdictsPartial = actorsPartial || !!data && (INCOMPLETE_COVERAGE_STATES.has(data.coverage.pools.state) || data.templates.some((t) => !t.matchingPoolsComplete))
75
+ const count = (n: number, inPart: boolean) => inPart ? n > 0 ? `≥${n}` : undefined : n
76
+ const rows = scoped.filter((t) => filter === 'all' || (filter === 'attention' ? needsAttention(t) : ready(t)))
77
+ .sort((a, b) => templateRank(a) - templateRank(b) || (b.attentionCount ?? 0) - (a.attentionCount ?? 0) || templateFilterValue(a).localeCompare(templateFilterValue(b)))
78
+ const columns: TableColumn<SubstrateTemplateRow>[] = [
79
+ {
80
+ header: 'Template',
81
+ width: '22%',
82
+ cell: (t) => (
83
+ <>
84
+ <Name name={t.name} />
85
+ <Sub><WholeNames text={t.atespace} /></Sub>
86
+ {kagentTemplateText(t.kagent) && <Sub><Tooltip content={kagentTemplateText(t.kagent)}><span>{t.kagent?.kind === 'agentSession' ? `kagent Agent ${agentText(t.kagent.agent)}` : 'kagent sandbox'}</span></Tooltip></Sub>}
87
+ </>
88
+ ),
89
+ },
90
+ {
91
+ header: <Term term="golden">Startup snapshot</Term>,
92
+ width: wide ? '24%' : '26%',
93
+ cell: (t) => (
94
+ <>
95
+ <GoldenBadge template={t} />
96
+ {t.golden.error ? (
97
+ <Tooltip content={t.golden.error} wrapperClassName="max-w-full">
98
+ <Sub><span className="line-clamp-3 break-words">{withoutReasonCode(t.golden.error)}</span></Sub>
99
+ </Tooltip>
100
+ ) : t.golden.time ? (
101
+ <Sub><When iso={t.golden.time} /></Sub>
102
+ ) : null}
103
+ </>
104
+ ),
105
+ },
106
+ {
107
+ header: 'Actors needing attention',
108
+ width: '19%',
109
+ cell: (t) => t.attentionCount === undefined || (actorsPartial && t.attentionCount === 0)
110
+ ? <Unread>Unknown</Unread>
111
+ : t.attentionCount > 0
112
+ ? <button type="button" onClick={(e) => { e.stopPropagation(); navigate(substrateActorsPath({ template: templateFilterValue(t), attention: '1' })) }} className="text-accent-text hover:underline">
113
+ {actorsPartial && <CertaintyGlyph certainty="lower_bound" title="Some actors or workers were not read" />}{t.attentionCount} →</button>
114
+ : '0',
115
+ },
116
+ { header: 'Label-matched pools', width: wide ? '16%' : '14%', cell: (t) => <PoolsCell t={t} /> },
117
+ { header: 'Per-actor resources', width: '15%', cell: (t) => resourcesText(t) },
118
+ { header: <span className="sr-only">Open template</span>, width: '76px', cell: (t) =>
119
+ <button type="button" aria-label={`Open template ${t.name}`} className="whitespace-nowrap text-xs text-accent-text hover:underline" onClick={(e) => { e.stopPropagation(); open(t) }}>Open →</button> },
120
+ ]
121
+ return (
122
+ <div className="flex min-h-0 flex-1 flex-col">
123
+ <SubstrateHeader title="Templates" intro="Cluster-wide · all atespaces" />
124
+ <ScreenBody>
125
+ {!connected && tier ? (
126
+ <>
127
+ <SubstrateTierBanner tier={tier} />
128
+ <SubstrateConnectNotice status={status} tier={tier} />
129
+ </>
130
+ ) : query.isLoading ? (
131
+ <PaneLoader label="Loading templates…" />
132
+ ) : !data ? (
133
+ <Notice>Radar couldn’t read the templates: {query.error instanceof Error ? query.error.message : 'unknown error'}.</Notice>
134
+ ) : (
135
+ <>
136
+ <RefreshFailedNotice queries={[query]} />
137
+ <SubstrateCoverageNotice coverage={data.coverage} kinds={['templates', 'actors', 'workers']} />
138
+ <div className="flex flex-wrap items-center gap-2">
139
+ <Segments label="Template filter" value={filter} onChange={setFilter} options={[
140
+ { id: 'all', label: 'All', count: count(scoped.length, partial) },
141
+ { id: 'attention', label: 'Needs attention', count: count(scoped.filter(needsAttention).length, partial || verdictsPartial) },
142
+ { id: 'ready', label: 'Ready', count: verdictsPartial ? undefined : count(scoped.filter(ready).length, partial) },
143
+ ]} />
144
+ <Input aria-label="Search templates" placeholder="Search templates…" value={search} onChange={(e) => setSearch(e.target.value)} className="h-8 max-w-52 rounded-md border border-theme-border bg-theme-elevated px-3" />
145
+ <SelectMenu ariaLabel="Atespace" value={atespace} onChange={setAtespace} options={[{ value: '', label: 'Every atespace' }, ...atespaces.map((value) => ({ value, label: value }))]} />
146
+ </div>
147
+ <SectionTable
148
+ columns={columns}
149
+ rows={rows}
150
+ rowKey={(t) => `${t.atespace}/${t.name}`}
151
+ rowResource={(t) => ({ kind: 'SubstrateTemplate', namespace: t.atespace, name: t.name })}
152
+ onInspect={(res) => open({ atespace: res.namespace, name: res.name })}
153
+ empty={data.templates.length && !rows.length ? 'No templates match these filters.' : coverageInPart(data.coverage.templates) ? `No templates: ${coverageReason(data.coverage.templates, 'templates')}.` : 'No templates.'}
154
+ minWidth={wide ? 900 : 720}
155
+ />
156
+ </>
157
+ )}
158
+ {tier && <SubstrateSourceLine tier={tier} status={status} />}
159
+ </ScreenBody>
160
+ </div>
161
+ )
162
+ }
163
+
164
+ /**
165
+ * What the template runs, read-only: its containers and images, volumes and
166
+ * snapshot settings. Env values Radar deems secret arrive redacted. A
167
+ * template is immutable, so this is exactly what each of its actors runs.
168
+ */
169
+ function TemplateSpec({ spec, unavailable, template }: { spec?: SubstrateTemplateSpec; unavailable?: string; template: SubstrateRef }) {
170
+ return (
171
+ <div>
172
+ {!spec ? (
173
+ <p className="text-sm text-theme-text-tertiary">Radar couldn’t read the spec{unavailable ? `: ${unavailable}` : ''}.</p>
174
+ ) : (
175
+ <div className="space-y-3">
176
+ <FactGrid>
177
+ {spec.createTime && <FactRow label="Created"><When iso={spec.createTime} /></FactRow>}
178
+ <FactRow label="Snapshots">
179
+ {fidelityLabel(spec.snapshot.preferredFidelity)} · stored in {spec.snapshot.storageLocation ? <span className="font-mono">{spec.snapshot.storageLocation}</span> : 'the API server’s default location'} · golden snapshot {spec.snapshot.golden}
180
+ <div className="text-xs text-theme-text-tertiary">The most a snapshot of its actors holds: a ceiling, not a guarantee. An actor’s own snapshot can hold less; its Snapshots tab says what each holds.</div>
181
+ </FactRow>
182
+ {spec.goldenEgressRules !== undefined && <FactRow label="Warm-up egress">{spec.goldenEgressRules} {spec.goldenEgressRules === 1 ? 'rule' : 'rules'} while the golden actor warms up</FactRow>}
183
+ <FactRow label="Volumes">
184
+ {spec.volumes.length ? spec.volumes.map((v) => `${v.name} (${v.kind === 'unknown' ? 'unknown type' : v.kind}${v.image ? ` ${v.image}` : ''})`).join(', ') : <span className="text-theme-text-secondary">none</span>}
185
+ </FactRow>
186
+ </FactGrid>
187
+ <div className="space-y-2">
188
+ {spec.containers.map((c) => (
189
+ <div key={c.name} className="card-inner">
190
+ <div className="flex flex-wrap items-baseline gap-x-2">
191
+ <span className="font-mono text-sm font-medium text-theme-text-primary">{c.name}</span>
192
+ <span className="min-w-0 break-all font-mono text-xs text-theme-text-secondary">{c.image}</span>
193
+ </div>
194
+ <dl className="mt-1 grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-0.5 text-xs">
195
+ {c.command?.length ? <><dt className="text-theme-text-tertiary">Command</dt><dd className="break-all font-mono">{c.command.join(' ')}</dd></> : null}
196
+ {c.args?.length ? <><dt className="text-theme-text-tertiary">Args</dt><dd className="break-all font-mono">{c.args.join(' ')}</dd></> : null}
197
+ {c.env?.length ? (
198
+ <>
199
+ <dt className="text-theme-text-tertiary">Env</dt>
200
+ <dd className="break-all font-mono">{c.env.map((e) => <div key={e.name}>{e.name}={e.redacted ? '(redacted)' : e.value}</div>)}</dd>
201
+ </>
202
+ ) : null}
203
+ {c.volumeMounts?.length ? <><dt className="text-theme-text-tertiary">Mounts</dt><dd className="break-all font-mono">{c.volumeMounts.map((m) => `${m.name} → ${m.mountPath}`).join(', ')}</dd></> : null}
204
+ {c.wakeupProbe ? <><dt className="text-theme-text-tertiary">Wake-up probe</dt><dd className="font-mono">{c.wakeupProbe}</dd></> : null}
205
+ </dl>
206
+ </div>
207
+ ))}
208
+ </div>
209
+ </div>
210
+ )}
211
+ <p className="mt-3 text-xs text-theme-text-tertiary">The template as Substrate stores it:</p>
212
+ <CommandChip command={templateYamlCommand(template)} />
213
+ </div>
214
+ )
215
+ }
216
+
217
+ /** A template's page: its golden snapshot, the actors of it by state, and the pools that can run it. */
218
+ export function SubstrateTemplatePage({ template, onOpenSubject }: { template: SubstrateRef; onOpenSubject: OpenSubject }) {
219
+ const navigate = useWorkspaceNavigate()
220
+ const pin = useContextPin()
221
+ const [params, setParams] = useSearchParams()
222
+ const tab = params.get('tab') === 'spec' ? 'spec' : 'overview'
223
+ const query = useSubstrateTemplate(pin.mismatch ? null : template)
224
+ // The same read the workspace frame holds; shared, not repeated.
225
+ const workspace = useSubstrateWorkspace(!pin.mismatch)
226
+ const code = substrateErrorCode(query.error)
227
+ // A refresh that says the template is gone or no longer readable replaces what was kept.
228
+ const t = definitiveFailure(code) ? undefined : query.data?.template
229
+ const crumb = (
230
+ <nav aria-label="Location" className="flex flex-wrap items-center gap-1.5 text-sm text-theme-text-tertiary">
231
+ <Bot className="h-3.5 w-3.5" />
232
+ <button type="button" onClick={() => navigate(SUBSTRATE_PATH)} className="hover:text-theme-text-primary hover:underline">Agent Substrate</button>
233
+ <span>/</span>
234
+ <button type="button" onClick={() => navigate(SUBSTRATE_SCREENS.templates.path)} className="hover:text-theme-text-primary hover:underline">Templates</button>
235
+ <span>/</span>
236
+ </nav>
237
+ )
238
+ if (pin.mismatch) {
239
+ return <NotInContext name={template.name} what={`template ${template.atespace} / ${template.name}`} pinnedContext={pin.pinned!} activeContext={pin.active} />
240
+ }
241
+ if (!t && query.isLoading) return <PaneLoader label={`Loading ${template.name}…`} className="flex-1" />
242
+ if (!t) {
243
+ const tier = code && code !== 'notFound' && code !== 'denied' ? tierReading({ state: 'failed', code, reason: query.error instanceof Error ? query.error.message : undefined }) : undefined
244
+ const title = code === 'notFound' ? `Substrate has no template ${template.name}` : code === 'denied' ? `Substrate denied reading ${template.name}` : tier?.title ?? `${template.name} couldn’t be read`
245
+ const detail = code === 'notFound'
246
+ ? `There is no template ${template.name} in atespace ${template.atespace}. It may have been deleted since this link was made.`
247
+ : tier
248
+ ? `${tier.detail}${tier.nextStep ? ` ${tier.nextStep}` : ''}`
249
+ : query.error instanceof Error ? query.error.message : 'Radar could not read the template.'
250
+ return (
251
+ <ScreenEmptyState
252
+ icon={Bot}
253
+ title={title}
254
+ detail={detail}
255
+ action={<button type="button" onClick={() => navigate(SUBSTRATE_SCREENS.templates.path)} className="btn-secondary mt-3 px-3 py-1.5 text-sm">Go to Templates</button>}
256
+ />
257
+ )
258
+ }
259
+ const golden = goldenReading(t)
260
+ const declaredNoPool = t.matchingPoolsComplete && t.matchingPools?.length === 0
261
+ const problems = (workspace.data?.needsAttention ?? []).filter((a) => a.subject.kind === 'ActorTemplate' && a.subject.atespace === t.atespace && a.subject.name === t.name)
262
+ const finding = problems[0]
263
+ const crashGroup = workspace.data?.needsAttention.find((a) => a.rule === 'crashedActors')?.groups?.find((g) => g.subject?.kind === 'ActorTemplate' && g.subject.atespace === t.atespace && g.subject.name === t.name)
264
+ const rebuild = t.golden.state === 'failed' && t.golden.cause === 'memoryLimit' && crashGroup?.cause === 'memoryLimit' && !crashGroup.kagent
265
+ const crashStep = rebuild ? memoryRebuildStep(crashGroup!.count) : crashGroup?.nextStep
266
+ const agent = t.kagent?.kind === 'agentSession' ? t.kagent.agent : undefined
267
+ const goldenStep = agent ? kagentGoldenStep(agent, t.golden.cause === 'memoryLimit') : undefined
268
+ const subject = { kind: 'ActorTemplate', namespace: t.atespace, group: '', name: t.name }
269
+ const [lead, rest] = finding ? splitReading(finding.reading) : []
270
+ const problem: WorkspaceProblem | undefined = finding ? {
271
+ id: finding.id, category: finding.rule, source: 'reading', origin: { label: 'Substrate API and WorkerPool labels' },
272
+ tone: attentionTone(finding), title: finding.rule === 'goldenSnapshotFailed' ? 'Startup snapshot failed' : 'No worker pool matches',
273
+ subject, detail: lead, rawDetail: rest || (t.golden.error ? withoutReasonCode(t.golden.error) : undefined),
274
+ nextStep: finding.rule === 'goldenSnapshotFailed' ? goldenStep ?? (rebuild ? crashStep : finding.nextStep) : finding.nextStep, rawDetailLabel: 'Details',
275
+ } : declaredNoPool || t.golden.state === 'failed' ? {
276
+ id: 'template', category: 'startup', source: 'reading', subject, origin: { label: 'Substrate API and WorkerPool labels' },
277
+ tone: declaredNoPool ? 'alert' : 'degraded',
278
+ title: declaredNoPool ? 'No worker pool matches' : 'Startup snapshot failed',
279
+ detail: declaredNoPool ? 'No pool’s labels match this template’s worker selector.' : 'New actors without a seed tag start from a cold boot. Substrate does not retry a failed build.',
280
+ nextStep: !declaredNoPool ? goldenStep : undefined,
281
+ rawDetail: t.golden.error ? withoutReasonCode(t.golden.error) : undefined, rawDetailLabel: 'Details',
282
+ } : undefined
283
+ const actorCoverage = query.data?.coverage.actors
284
+ const actorsPartial = coverageInPart(actorCoverage) || coverageInPart(query.data?.coverage.workers)
285
+ const actorNote = t.attentionCount === undefined || (actorsPartial && t.attentionCount === 0) ? 'Unknown' : `${actorsPartial ? '≥' : ''}${t.attentionCount} need attention`
286
+ const selector = Object.entries(t.workerSelector ?? {}).map(([k, v]) => `${k}=${v}`).join(', ')
287
+ const config = <TemplateSpec spec={query.data?.spec} unavailable={query.data?.specUnavailable} template={t} />
288
+ return (
289
+ <DetailShell
290
+ identity={<div className="flex flex-wrap items-center gap-2">
291
+ {crumb}
292
+ <h1 className="min-w-0 break-all font-mono text-lg font-semibold text-theme-text-primary">{t.name}</h1>
293
+ <GoldenBadge template={t} named />
294
+ <span className="text-sm text-theme-text-secondary"><Term term="atespace">Atespace</Term>: {t.atespace}</span>
295
+ </div>}
296
+ headerActions={<button type="button" onClick={() => void query.refetch()} disabled={query.isFetching} aria-label="Refresh" className="rounded p-1.5 text-theme-text-secondary hover:bg-theme-hover disabled:opacity-50"><RefreshCw size={18} /></button>}
297
+ tabs={[{ id: 'overview', label: 'Overview', icon: <LayoutDashboard size={16} /> }, { id: 'spec', label: 'Spec', icon: <FileCode size={16} /> }]}
298
+ activeTab={tab}
299
+ onTabChange={(id) => setParams((p) => {
300
+ const next = new URLSearchParams(p)
301
+ if (id === 'overview') next.delete('tab')
302
+ else next.set('tab', id)
303
+ return next
304
+ }, { replace: true })}
305
+ >
306
+ <ScreenBody>
307
+ <RefreshFailedNotice queries={[query]} />
308
+ {tab === 'spec' ? <WorkspaceCard title="Template configuration">{config}</WorkspaceCard> : <>
309
+ {problem && <WorkspaceProblemCallout problem={problem} rootKind="ActorTemplate" subjectIsSelf more={
310
+ (finding?.command || problems.length > 1) && <FoldSection title={problems.length > 1 ? `Details · +${problems.length - 1} more` : 'Recovery steps'} summary="" attention={false}>
311
+ {finding?.command && <CommandChip command={finding.command} />}
312
+ {problems.slice(1).map((p) => <p key={p.id} className="text-xs text-theme-text-secondary">{p.title}. {p.reading}</p>)}
313
+ </FoldSection>
314
+ } />}
315
+ <WorkspaceCard title="At a glance">
316
+ <FactGrid>
317
+ {kagentTemplateText(t.kagent) && (
318
+ <FactRow label="kagent">
319
+ {agent ? (
320
+ <>
321
+ Agent{' '}
322
+ <button type="button" onClick={() => onOpenSubject({ kind: 'Agent', namespace: agent.namespace, name: agent.name })} className="font-mono text-accent-text hover:underline">
323
+ {agentText(agent)}
324
+ </button>
325
+ <div className="text-xs text-theme-text-secondary">{kagentTemplateText(t.kagent)}. kagent creates one template per revision and owns it.</div>
326
+ </>
327
+ ) : (
328
+ <span>{kagentTemplateText(t.kagent)}</span>
329
+ )}
330
+ </FactRow>
331
+ )}
332
+ <FactRow label={<Term term="golden">Startup snapshot</Term>}>
333
+ <DimensionValue tone={declaredNoPool ? 'alert' : golden.severity === 'success' ? 'healthy' : golden.severity === 'warning' ? 'degraded' : 'neutral'}
334
+ source={<>Substrate template{t.golden.time && <> · <When iso={t.golden.time} prefix="updated" /></>}{t.golden.state === 'ready' && ' · New actors start from the golden snapshot'}</>}>
335
+ {t.golden.state === 'failed' ? 'Failed · cold startup' : t.golden.state === 'ready' ? 'Ready' : golden.label}
336
+ </DimensionValue>
337
+ </FactRow>
338
+ <FactRow label="Placement">
339
+ <DimensionValue tone={declaredNoPool ? 'alert' : t.matchingPools === null ? 'unknown' : 'neutral'}
340
+ source="WorkerPool labels and template selector · placement also requires capacity and a compatible runtime">
341
+ <PoolsCell t={t} />
342
+ </DimensionValue>
343
+ {t.matchingPools && <PoolMatchLinks pools={t.matchingPools} workspace={workspace.data} />}
344
+ </FactRow>
345
+ <FactRow label="Actors">
346
+ <DimensionValue tone={t.actors?.byState.crashed ? 'unhealthy' : t.attentionCount ? 'alert' : actorNote === 'Unknown' ? 'unknown' : 'neutral'}
347
+ source={t.actors && (!coverageInPart(actorCoverage) || t.actors.total > 0)
348
+ ? `Reported by Substrate · ${coverageInPart(actorCoverage) ? '≥' : ''}${t.actors.total} actors` : coverageReason(actorCoverage, 'actors')}
349
+ linkLabel="Actors needing attention" onOpen={() => onOpenSubject({ kind: 'Actors', filter: { template: templateFilterValue(t), attention: '1' } })}>
350
+ {actorNote}
351
+ </DimensionValue>
352
+ {!!t.actors?.byState.crashed && <button type="button" className="text-xs text-accent-text hover:underline"
353
+ onClick={() => onOpenSubject({ kind: 'Actors', filter: { template: templateFilterValue(t), state: 'crashed' } })}>
354
+ {coverageInPart(actorCoverage) ? '≥' : ''}{t.actors.byState.crashed} reported crashed →
355
+ </button>}
356
+ {crashGroup && crashStep && <FoldSection title="Crash recovery steps" summary={crashGroup.cause === 'memoryLimit' ? t.memoryBytes ? `Killed over the ${bytesText(t.memoryBytes)} memory limit per actor` : 'Killed over their memory limit' : 'Review the crash causes'} attention={false}>
357
+ {!rebuild && <p className="text-xs text-theme-text-secondary">{crashStep}</p>}
358
+ {!crashGroup.kagent && crashGroup.command && <CommandChip command={crashGroup.command} />}
359
+ {!crashGroup.kagent && crashGroup.command && crashGroup.thenCommand && <CommandChip command={crashGroup.thenCommand} />}
360
+ </FoldSection>}
361
+ </FactRow>
362
+ </FactGrid>
363
+ </WorkspaceCard>
364
+ <WorkspaceCard title="About">
365
+ <FactGrid>
366
+ <FactRow label="Per-actor resources">{resourcesText(t)}</FactRow>
367
+ <FactRow label="Worker selector">{selector ? <span className="font-mono">{selector}</span> : 'No label constraints'}</FactRow>
368
+ <FactRow label="Snapshot fidelity">{fidelityLabel(t.preferredFidelity)}</FactRow>
369
+ </FactGrid>
370
+ </WorkspaceCard>
371
+
372
+ </>}
373
+ </ScreenBody>
374
+ </DetailShell>
375
+ )
376
+ }
@@ -0,0 +1,173 @@
1
+ import { useCallback } from 'react'
2
+ import { useLocation, useSearchParams } from 'react-router-dom'
3
+ import type { WorkspaceScreenProps } from '../../integrations/workspaceRoute'
4
+ import { useAPIResources } from '../../api/apiResources'
5
+ import { useSubstrateConnection, useSubstrateStatus, useSubstrateWorkspace, type SubstrateRef, type SubstrateSubject } from '../../api/substrateWorkspace'
6
+ import { useConnection } from '../../context/ConnectionContext'
7
+ import { useMediaQuery } from '../../hooks/useMediaQuery'
8
+ import { currentPageLabel } from '../../utils/page-links'
9
+ import { refToSelectedResource } from '../../utils/navigation'
10
+ import { encodeDrawerTrail } from '../../utils/drawer-trail'
11
+ import type { SelectedResource } from '../../types'
12
+ import { useIntegrationSidebars } from '../../integrations/sidebarWorkspaces'
13
+ import { WorkspaceFrame } from '../workspace/WorkspaceFrame'
14
+ import { useWorkspaceDrawer } from '../workspace/useWorkspaceDrawer'
15
+ import { useWorkspaceNavigate } from '../workspace/useWorkspaceNavigate'
16
+ import {
17
+ ACTOR_DRAWER_PARAM,
18
+ SUBSTRATE_GROUP,
19
+ SUBSTRATE_WORKERPOOL_KIND,
20
+ decodeActorParam,
21
+ encodeActorParam,
22
+ parseSubstrateRoute,
23
+ substrateActorPath,
24
+ substrateActorsPath,
25
+ substrateTemplatePath,
26
+ } from './routes'
27
+ import { SubstrateActorDrawer } from './SubstrateActorDrawer'
28
+ import { SubstrateActorPage } from './SubstrateActorPage'
29
+ import { SubstrateActorsScreen } from './SubstrateActors'
30
+ import { SubstrateOverview } from './SubstrateOverview'
31
+ import { SubstratePoolPage } from './SubstratePoolPage'
32
+ import { SubstrateTemplatePage, SubstrateTemplatesScreen } from './SubstrateTemplates'
33
+ import { SubstrateWorkersScreen } from './SubstrateWorkers'
34
+ import { KubectlTargetContext, substrateKubectlTarget, SubstrateScreenGate } from './shared'
35
+ import { KAGENT_GROUP } from '../kagent/routes'
36
+ import { substrateDiscovered } from './useSubstrateSidebarWorkspace'
37
+
38
+ /**
39
+ * One drawer at a time, in one URL update each way: opening an actor's drawer
40
+ * closes the resource drawer, and opening a resource closes the actor's. Two
41
+ * writes from one render each start from the same old params, so the second
42
+ * would bring the first drawer back.
43
+ */
44
+ export function actorDrawerParams(params: URLSearchParams, actor: SubstrateRef | null): URLSearchParams {
45
+ const p = new URLSearchParams(params)
46
+ if (actor) {
47
+ p.set(ACTOR_DRAWER_PARAM, encodeActorParam(actor))
48
+ p.delete('drawer')
49
+ } else {
50
+ p.delete(ACTOR_DRAWER_PARAM)
51
+ }
52
+ return p
53
+ }
54
+
55
+ export function resourceDrawerParams(params: URLSearchParams, resource: SelectedResource): URLSearchParams {
56
+ const p = new URLSearchParams(params)
57
+ p.delete(ACTOR_DRAWER_PARAM)
58
+ p.set('drawer', encodeDrawerTrail([resource]))
59
+ return p
60
+ }
61
+
62
+ /**
63
+ * The Agent Substrate workspace: Overview, Actors, Templates, Workers and the
64
+ * pages of actors, templates and WorkerPools. It lives inside Resources with
65
+ * the same sidebar. Actors live in atespaces, so the namespace picker does
66
+ * not apply; the screens have an Atespace filter instead.
67
+ */
68
+ export function SubstrateView({ namespaces, selectedResource, onOpenResource, onCloseResource }: WorkspaceScreenProps) {
69
+ const location = useLocation()
70
+ const route = parseSubstrateRoute(location.pathname)
71
+ const navigate = useWorkspaceNavigate()
72
+ const [params, setParams] = useSearchParams()
73
+ const { connection } = useConnection()
74
+ const narrow = useMediaQuery('(max-width: 1100px)')
75
+ const laptop = useMediaQuery('(max-width: 1300px)')
76
+ const onPage = !!(route.actor || route.template || route.pool)
77
+ const compactNavigation = narrow || (laptop && onPage)
78
+ const { data: apiResources, isPending: discoveryPending, isError: discoveryFailed } = useAPIResources()
79
+ // Discovery that could not be read does not say Substrate is absent; the server is asked then.
80
+ const discovered = substrateDiscovered(apiResources) || discoveryFailed
81
+ const status = useSubstrateStatus(discovered)
82
+ const workspace = useSubstrateWorkspace(discovered)
83
+
84
+ const sidebarWorkspace = useIntegrationSidebars({ apiResources, namespaces, substrate: { active: route.pool ? undefined : route.screen } })
85
+ const selectedKind = route.pool ? SUBSTRATE_WORKERPOOL_KIND : null
86
+ const { inspect } = useWorkspaceDrawer({ selectedResource, onOpenResource, onCloseResource })
87
+ const connectionView = useSubstrateConnection(discovered)
88
+ const kubectlTarget = connectionView.isError
89
+ ? { guidance: 'Use a client configured for the Substrate instance on this cluster.' }
90
+ : substrateKubectlTarget(connectionView.data, connection.context)
91
+
92
+ const openActor = decodeActorParam(params.get(ACTOR_DRAWER_PARAM))
93
+ const setActorDrawer = useCallback(
94
+ (actor: SubstrateRef | null) => setParams(actorDrawerParams(params, actor), { replace: true, state: location.state }),
95
+ [params, setParams, location.state],
96
+ )
97
+ const inspectResource = useCallback(
98
+ (resource: SelectedResource) => {
99
+ if (params.has(ACTOR_DRAWER_PARAM)) setParams(resourceDrawerParams(params, resource), { replace: true, state: location.state })
100
+ else inspect(resource)
101
+ },
102
+ [inspect, params, setParams, location.state],
103
+ )
104
+ const openFull = useCallback(
105
+ (actor: SubstrateRef, tab?: string) => navigate(substrateActorPath(actor, connection.context || undefined, tab), { state: { returnLabel: currentPageLabel(), returnCtx: connection.context } }),
106
+ [navigate, connection.context],
107
+ )
108
+
109
+ // What a link names: an actor list, an actor (its drawer, or its page from
110
+ // an actor's page), a template's page, or a Kubernetes object's drawer.
111
+ const openSubject = useCallback(
112
+ (s: SubstrateSubject) => {
113
+ switch (s.kind) {
114
+ case 'Actors':
115
+ navigate(substrateActorsPath(s.filter))
116
+ return
117
+ case 'Actor':
118
+ if (s.atespace && s.name) {
119
+ if (route.actor) openFull({ atespace: s.atespace, name: s.name })
120
+ else setActorDrawer({ atespace: s.atespace, name: s.name })
121
+ }
122
+ return
123
+ case 'ActorTemplate':
124
+ if (s.atespace && s.name) navigate(substrateTemplatePath({ atespace: s.atespace, name: s.name }, connection.context || undefined))
125
+ return
126
+ case 'WorkerPool':
127
+ inspectResource(refToSelectedResource({ kind: 'WorkerPool', group: SUBSTRATE_GROUP, namespace: s.namespace ?? '', name: s.name ?? '' }))
128
+ return
129
+ case 'Worker':
130
+ case 'Pod':
131
+ inspectResource(refToSelectedResource({ kind: 'Pod', group: '', namespace: s.namespace ?? '', name: s.name ?? '' }))
132
+ return
133
+ case 'Node':
134
+ inspectResource(refToSelectedResource({ kind: 'Node', group: '', namespace: '', name: s.name ?? '' }))
135
+ return
136
+ case 'Agent':
137
+ inspectResource(refToSelectedResource({ kind: 'Agent', group: KAGENT_GROUP, namespace: s.namespace ?? '', name: s.name ?? '' }))
138
+ }
139
+ },
140
+ [navigate, route.actor, openFull, setActorDrawer, inspectResource, connection.context],
141
+ )
142
+
143
+ const screen = (() => {
144
+ if (route.actor) return <SubstrateActorPage actor={route.actor} onOpenSubject={openSubject} />
145
+ if (route.template) return <SubstrateTemplatePage template={route.template} onOpenSubject={openSubject} />
146
+ if (route.pool) return <SubstratePoolPage pool={route.pool} onOpenResource={inspectResource} />
147
+ return (
148
+ <SubstrateScreenGate query={workspace} discoveryPending={discoveryPending} discovered={discovered}>
149
+ {(data) => {
150
+ switch (route.screen) {
151
+ case 'actors':
152
+ return <SubstrateActorsScreen workspace={data} status={status.data} onOpenActor={setActorDrawer} openActor={openActor} />
153
+ case 'templates':
154
+ return <SubstrateTemplatesScreen workspace={data} status={status.data} />
155
+ case 'workers':
156
+ return <SubstrateWorkersScreen workspace={data} status={status.data} onOpenSubject={openSubject} />
157
+ default:
158
+ return <SubstrateOverview data={data} status={status.data} onOpenSubject={openSubject} />
159
+ }
160
+ }}
161
+ </SubstrateScreenGate>
162
+ )
163
+ })()
164
+
165
+ return (
166
+ <KubectlTargetContext.Provider value={kubectlTarget}>
167
+ <WorkspaceFrame namespaces={namespaces} categoryWorkspaces={sidebarWorkspace} selectedKind={selectedKind} compactNavigation={compactNavigation}>
168
+ {screen}
169
+ <SubstrateActorDrawer actor={route.actor ? null : openActor} onClose={() => setActorDrawer(null)} onOpenFull={openFull} onOpenSubject={openSubject} />
170
+ </WorkspaceFrame>
171
+ </KubectlTargetContext.Provider>
172
+ )
173
+ }
@@ -0,0 +1,73 @@
1
+ import { FactGrid, FactRow, WorkspaceCard, formatDuration } from '@skyhook-io/k8s-ui'
2
+ import { substrateErrorCode, useSubstrateWorkers } from '../../api/substrateWorkspace'
3
+ import { useConnection } from '../../context/ConnectionContext'
4
+ import { useWorkspaceNavigate } from '../workspace/useWorkspaceNavigate'
5
+ import { slotsText } from './SubstratePoolSummary'
6
+ import { coverageInPart, coverageReason, definitiveFailure, tierReading } from './readings'
7
+ import { substrateActorsPath, substratePoolPath } from './routes'
8
+ import { WorkerStateChip } from './shared'
9
+
10
+ export function SubstrateWorkerPodContext({ namespace, pool, pod, resource, framed = false }: {
11
+ namespace: string
12
+ pool: string
13
+ pod: string
14
+ framed?: boolean
15
+ resource: { metadata?: { deletionTimestamp?: string }; status?: { conditions?: { type: string; status: string }[] } }
16
+ }) {
17
+ const poolKey = `${namespace}/${pool}`
18
+ const query = useSubstrateWorkers(poolKey)
19
+ const { connection } = useConnection()
20
+ const navigate = useWorkspaceNavigate()
21
+ const code = substrateErrorCode(query.error)
22
+ const data = definitiveFailure(code) ? undefined : query.data
23
+ const failure = code ? tierReading({ state: 'failed', code, reason: query.error?.message }) : undefined
24
+ const worker = data?.workers.find((w) => w.namespace === namespace && w.pool === pool && w.pod === pod)
25
+ const ready = resource.status?.conditions?.find((c) => c.type === 'Ready')?.status
26
+ const podState = resource.metadata?.deletionTimestamp ? 'Kubernetes Pod terminating'
27
+ : ready === 'True' ? 'Kubernetes Pod ready' : ready === 'False' ? 'Kubernetes Pod not ready' : 'Kubernetes Pod readiness unreported'
28
+ const absent = query.isLoading ? 'Reading Substrate worker state…'
29
+ : failure && !data ? [failure.detail, failure.nextStep].filter(Boolean).join(' ')
30
+ : query.error && !data ? query.error.message
31
+ : !data ? 'Substrate worker state unavailable'
32
+ : coverageInPart(data.coverage.workers) ? coverageReason(data.coverage.workers, 'workers')
33
+ : 'No worker registration reported for this Pod'
34
+ const actorsPartial = coverageInPart(data?.coverage.actors)
35
+ const assigned = worker?.actors?.length
36
+ return (
37
+ <WorkspaceCard title="Substrate worker" framed={framed}>
38
+ <FactGrid>
39
+ <FactRow label="State">
40
+ {worker ? <><WorkerStateChip w={worker} />{worker.heldForSeconds !== undefined && <span className="ml-1.5 text-xs text-theme-text-tertiary">for at least {formatDuration(worker.heldForSeconds * 1000)}</span>}</> : <span className="text-theme-text-secondary">{absent}</span>}
41
+ <span className="ml-1.5 text-xs text-theme-text-secondary">· {podState}</span>
42
+ </FactRow>
43
+ <FactRow label="Pool">
44
+ <button type="button" className="font-mono text-accent-text hover:underline" onClick={() => navigate(substratePoolPath({ namespace, name: pool }, connection.context || undefined))}>{pool} →</button>
45
+ {worker && <span className="text-xs text-theme-text-tertiary"> · {slotsText(worker)}</span>}
46
+ </FactRow>
47
+ {worker && <FactRow label="Assignments">
48
+ <button type="button" className="text-accent-text hover:underline" onClick={() => navigate(substrateActorsPath({ pool: poolKey, worker: worker.name }))}>
49
+ {assigned === undefined || (actorsPartial && assigned === 0) ? 'View assigned actors' : `Show ${actorsPartial ? '≥' : ''}${assigned} assigned ${assigned === 1 ? 'actor' : 'actors'}`} →
50
+ </button>
51
+ </FactRow>}
52
+ </FactGrid>
53
+ <p className="mt-2 text-xs text-theme-text-tertiary">Pod logs, metrics and restarts cover the shared worker process.</p>
54
+ </WorkspaceCard>
55
+ )
56
+ }
57
+
58
+ export function SubstrateWorkerPodScope({ namespace, pool, pod, tab }: {
59
+ namespace: string
60
+ pool: string
61
+ pod: string
62
+ tab: 'logs' | 'metrics'
63
+ }) {
64
+ const navigate = useWorkspaceNavigate()
65
+ return (
66
+ <p className="text-xs text-theme-text-secondary">
67
+ These {tab} cover the shared worker Pod across all actors it hosts.{' '}
68
+ <button type="button" className="text-accent-text hover:underline" onClick={() => navigate(substrateActorsPath({ pool: `${namespace}/${pool}`, worker: pod }))}>
69
+ View assigned actors →
70
+ </button>
71
+ </p>
72
+ )
73
+ }