Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
its track and the footer ended up overlapping the last row at 390px
(UX audit F14). -->
<main class="overflow-y-auto min-h-0 min-w-0 p-4 sm:p-6">
<router-view />
<!-- #1065: keyed on authEpoch so repairing a failed auth remounts the
current view. Views hold their load errors in component-local refs
that nothing outside can reach, so a successful sign-in used to
leave a stale red error panel and zero rows behind the recovered
header. Key on authEpoch ONLY -- folding in the route path would
remount ServerDetail on every :serverName change and break the
Dashboard's single instance across /, /usage and /overview. -->
<router-view :key="systemStore.authEpoch" />
</main>

<!-- Persistent footer with project links (discussion #948) -->
Expand Down Expand Up @@ -79,24 +86,44 @@ function handleAuthModalClose() {
systemStore.setAuthRequired(false)
}

// Re-prime everything that only loads at mount. The <router-view> key covers
// the routed view, but these surfaces live outside it and would otherwise keep
// their failed state until a full page reload (#1065).
async function reloadAfterAuth() {
systemStore.connectEventSource()
serversStore.fetchServers()
systemStore.fetchInfo() // TopHeader version / update state
systemStore.fetchRouting() // TopHeader routing chip
// Server-edition role-based nav. The router guard does not run for a
// key-driven remount, so re-check here.
await authStore.checkAuth()
}

function handleAuthModalAuthenticated() {
authModal.show = false
authModal.lastError = ''
systemStore.setAuthRequired(false)
// markAuthRecovered, not setAuthRequired(false): this path validated the key,
// so it is safe to invalidate every view that failed while auth was broken.
systemStore.markAuthRecovered()

// Refresh data now that we're authenticated
systemStore.connectEventSource()
serversStore.fetchServers()
void reloadAfterAuth()
}

function handleAuthModalRefresh() {
function handleAuthModalRefresh(verified: boolean) {
if (!verified) {
// The reloaded key did not authenticate. Leave the modal and the
// auth-required flag in place rather than remounting every view onto a
// key that is still 401.
return
}

authModal.show = false
authModal.lastError = ''
systemStore.setAuthRequired(false)
// The modal verified the reloaded key, so this is a real recovery and the
// views holding stale auth errors must be invalidated too (#1065).
systemStore.markAuthRecovered()

// Reconnect with potentially new API key
systemStore.connectEventSource()
serversStore.fetchServers()
void reloadAfterAuth()
}

// Handle API authentication errors
Expand Down
13 changes: 1 addition & 12 deletions frontend/src/components/ActivityWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import api from '@/services/api'
import type { ActivityRecord, ActivitySummaryResponse } from '@/types/api'
import {
formatPreflightSummary,
getTypeIcon,
isChildCall,
isPreflightActivity,
statusPresentation,
Expand Down Expand Up @@ -161,18 +162,6 @@ const formatRelativeTime = (timestamp: string): string => {
return `${Math.floor(diff / 86400000)}d ago`
}

const getTypeIcon = (type: string): string => {
const typeIcons: Record<string, string> = {
'tool_call': '🔧',
'policy_decision': '🛡️',
'quarantine_change': '⚠️',
'server_change': '🔄',
// Spec 098: required-tools preflight
'preflight': '🛫'
}
return typeIcons[type] || '📋'
}

// Lifecycle
onMounted(() => {
loadData()
Expand Down
29 changes: 24 additions & 5 deletions frontend/src/components/AuthErrorModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ interface Props {
interface Emits {
(e: 'close'): void
(e: 'authenticated'): void
(e: 'refresh'): void
// `verified` says whether the reloaded key actually authenticated. App.vue
// only invalidates views when it did (#1065).
(e: 'refresh', verified: boolean): void
}

const props = withDefaults(defineProps<Props>(), {
Expand Down Expand Up @@ -175,10 +177,27 @@ async function handleSetAPIKey() {
}
}

function handleRefresh() {
// Reinitialize API key from URL/localStorage
api.reinitializeAPIKey()
emit('refresh')
async function handleRefresh() {
// Reinitialize API key from URL/localStorage, then VERIFY it before telling
// the app auth is repaired. Without the verification this path could only
// assert recovery, so it could not safely invalidate the views holding stale
// auth errors -- and #1065's stale red panel survived on this path.
isValidating.value = true
inputError.value = ''
try {
api.reinitializeAPIKey()
const isValid = await api.validateAPIKey()
emit('refresh', isValid)
if (!isValid) {
inputError.value = 'No valid API key found — enter one above'
}
} catch (error) {
console.error('API key refresh error:', error)
inputError.value = error instanceof Error ? error.message : 'Refresh failed'
emit('refresh', false)
} finally {
isValidating.value = false
}
}

function handleClose() {
Expand Down
52 changes: 48 additions & 4 deletions frontend/src/components/ServerCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@
<!-- Security scan badge (Spec 039)
Wrapped in a DaisyUI tooltip that explains the state and carries a
disclaimer that the risk score is an experimental heuristic. -->
<div v-if="server.security_scan" class="flex items-center gap-2 mb-4">
<!-- #1065: hidden while the server is quarantined. A scan verdict is
about CONTENT; quarantine is about REVIEW STATE. Stacked as siblings
they read as contradictory claims about the same server ("Clean"
directly above "needs security review"). While quarantined the
verdict is folded into the banner below as a subordinate clause, so
the card carries exactly one security headline -- the subordination
ServerDetail's spec-088 banner already does. -->
<div v-if="server.security_scan && !server.quarantined" class="flex items-center gap-2 mb-4">
<div
class="flex items-center gap-1.5 text-sm tooltip tooltip-right tooltip-bottom max-w-xs"
:data-tip="securityBadgeTooltip"
Expand Down Expand Up @@ -147,11 +154,18 @@
("needs security review") so it must also afford it — Review opens the
server's Security tab, where the spec-088 banner carries the verdict
and the approve/scan actions. -->
<div v-if="server.quarantined" class="alert alert-warning alert-sm mb-4" data-test="server-card-quarantine">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<div v-if="server.quarantined" class="alert alert-warning alert-sm mb-4 items-start" data-test="server-card-quarantine">
<svg class="w-4 h-4 mt-0.5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.732-.833-2.5 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z" />
</svg>
<span class="text-xs flex-1">Quarantined — needs security review</span>
<div class="min-w-0 flex-1">
<div class="text-xs">Quarantined — needs security review</div>
<div
v-if="quarantineScanNote"
class="text-[11px] opacity-80 mt-0.5"
data-test="server-card-quarantine-scan-note"
>{{ quarantineScanNote }}</div>
</div>
<router-link
:to="serverDetailPath(server.name, 'security')"
class="btn btn-xs btn-warning"
Expand Down Expand Up @@ -696,6 +710,36 @@ const securityBadgeTooltip = computed(() => {
}
})

// #1065: the subordinate half of the quarantine banner. Same reasoning as the
// #938 held-tools downgrade above, one level up -- a reassuring statement must
// never sit as a peer of a warning one. While quarantined the standalone badge
// is suppressed and its verdict is restated here as a clause of the quarantine
// headline: the verdict informs the review, it does not settle it. Returns ''
// when there is nothing worth saying, keeping the banner a one-liner.
const quarantineScanNote = computed(() => {
const scan = props.server.security_scan
const status = scan?.status
if (!scan || !status || status === 'not_scanned') return ''
switch (status) {
case 'scanning':
return 'Security scan in progress…'
case 'failed':
// A failed scan is an INCOMPLETE scan, never a threat verdict -- mirrors
// the scan-failed precaution branch in utils/quarantineBanner.ts.
return 'Last scan could not complete — still needs review'
case 'clean':
return 'Last scan: clean — still needs review'
case 'warnings': {
const n = scan.finding_counts?.warning ?? 0
return `Last scan: ${n} warning${n !== 1 ? 's' : ''} — needs review`
}
case 'dangerous':
return 'Last scan: dangerous findings — needs review'
default:
return ''
}
})

// Determine if error message should be shown (FR-018, FR-019)
// Suppress verbose last_error when health.action already conveys the issue
const shouldShowError = computed(() => {
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/components/SidebarNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@
</template>

<script setup lang="ts">
import { computed, h, onMounted, ref, type FunctionalComponent } from 'vue'
import { computed, h, onMounted, ref, watch, type FunctionalComponent } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useSystemStore } from '@/stores/system'
import { formatDateTime } from '@/utils/datetime'
Expand Down Expand Up @@ -518,16 +518,25 @@ function onClickSetup() {
}
}

onMounted(() => {
// Pull initial state so the badge is correct on first render. Personal-
// edition only — the surrounding template gates this for personal users.
function loadBadgeCounts() {
// Personal-edition only — the surrounding template gates this for personal users.
if (!authStore.isTeamsEdition) {
void onboardingStore.fetchState()
void fetchToolCount()
void fetchSecretCount()
}
}

onMounted(() => {
// Pull initial state so the badge is correct on first render.
loadBadgeCounts()
})

// #1065: the sidebar sits outside <router-view>, so App.vue's authEpoch key
// cannot remount it. Without this, badge counts that failed while auth was
// broken keep their stale values until a full page reload.
watch(() => systemStore.authEpoch, loadBadgeCounts)

const collapsed = computed(() => systemStore.sidebarCollapsed)

// "System" is rendered on its own above the divider; the rest are the explicit
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/stores/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ export const useServersStore = defineStore('servers', () => {
servers.value.filter(s => s.quarantined)
)

// Only count tools from enabled servers (Issue #285 fix)
// Only count tools that are actually available: enabled servers (Issue #285)
// that are not quarantined (Issue #1064 -- a quarantined server's tools are
// refused at dispatch and purged from the search index, so counting them
// tells the operator N tools are available when none of them are callable).
const totalTools = computed(() =>
servers.value
.filter(s => s.enabled)
.filter(s => s.enabled && !s.quarantined)
.reduce((sum, server) => sum + server.tool_count, 0)
)

Expand Down
22 changes: 22 additions & 0 deletions frontend/src/stores/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,30 @@ export const useSystemStore = defineStore('system', () => {
// owns the message too; the downstream surfaces read this flag and stay quiet.
const authRequired = ref(false)

// Bumped when a failed auth is repaired with a VALIDATED key (#1065). Views
// keep their load errors in component-local refs that nothing outside the
// component can reach, so signing in left the header re-authenticated while
// the view body kept a red "Invalid or missing API key" panel and zero rows
// until the user clicked Retry by hand. App.vue keys <router-view> on this,
// so a repaired auth remounts the current view: its error, loading state and
// data reset to their declared initial values and onMounted re-runs.
const authEpoch = ref(0)

function setAuthRequired(value: boolean) {
authRequired.value = value
}

// Clear the auth-required flag AND invalidate the views that failed while it
// was set. Only for paths that actually verified the new key -- a path that
// merely re-reads the key from disk must use setAuthRequired(false), or every
// view remounts onto a possibly-still-401 epoch.
function markAuthRecovered() {
if (authRequired.value) {
authEpoch.value++
}
authRequired.value = false
}

// Available themes. `system` leads the list and is the default: a user on a
// dark OS should not get a light UI on first run (UX audit F29).
const themes: Theme[] = [
Expand Down Expand Up @@ -584,6 +604,7 @@ export const useSystemStore = defineStore('system', () => {
checkingForUpdates,
updateCheckedAt,
authRequired,
authEpoch,

// Computed
isRunning,
Expand Down Expand Up @@ -612,5 +633,6 @@ export const useSystemStore = defineStore('system', () => {
fetchRouting,
checkForUpdates,
setAuthRequired,
markAuthRecovered,
}
})
47 changes: 41 additions & 6 deletions frontend/src/utils/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,39 @@

import { formatDateTime } from './datetime'

// Activity type labels
const typeLabels: Record<string, string> = {
// Activity type labels.
//
// Keyed by every constant in internal/storage/activity_models.go — a backend
// type with no entry here used to fall through the old `|| type` passthrough
// and paint the raw storage enum into the Activity table's Type column, beside
// title-cased prose (#1065). internal/storage/activity_label_parity_test.go
// fails if a new backend type is added without a label here. Declaration order
// is the filter-dropdown order.
export const ACTIVITY_TYPE_LABELS: Record<string, string> = {
'tool_call': 'Tool Call',
'system_start': 'System Start',
'system_stop': 'System Stop',
'internal_tool_call': 'Internal Tool Call',
'config_change': 'Config Change',
'policy_decision': 'Policy Decision',
// Server-level quarantine. Deliberately NOT the same label as
// tool_quarantine_change below: collapsing the two is a real defect in the
// macOS tray's copy of this table.
'quarantine_change': 'Quarantine Change',
'server_change': 'Server Change',
// Spec 098: one executed required-tools preflight.
'preflight': 'Preflight'
'preflight': 'Preflight',
// --- #1065: these four were emitted by the backend with no label ---
'tool_quarantine_change': 'Tool Quarantine Change', // Spec 032, tool-level
'security_scan': 'Security Scan', // Spec 077
'credential_broker': 'Credential Broker', // Spec 074, server edition only
'prompt_get': 'Prompt Fetch'
}

// Activity type icons
const typeLabels = ACTIVITY_TYPE_LABELS

// Activity type icons. Same keys as ACTIVITY_TYPE_LABELS; each distinct, so a
// glyph identifies the type on its own.
const typeIcons: Record<string, string> = {
'tool_call': '🔧',
'system_start': '🚀',
Expand All @@ -29,7 +47,11 @@ const typeIcons: Record<string, string> = {
'policy_decision': '🛡️',
'quarantine_change': '⚠️',
'server_change': '🔄',
'preflight': '🛫'
'preflight': '🛫',
'tool_quarantine_change': '🧪',
'security_scan': '🔎',
'credential_broker': '🔑',
'prompt_get': '💬'
}

// Status labels
Expand Down Expand Up @@ -64,11 +86,24 @@ const intentClasses: Record<string, string> = {
'destructive': 'badge-error'
}

/**
* snake_case -> Title Case. The last-resort fallback for formatType, so a
* backend value that has not been given a label yet still reads as prose
* instead of leaking the raw storage enum (#1065).
*/
export const humaniseType = (type: string): string => {
return type
.split('_')
.filter(Boolean)
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ')
}

/**
* Format activity type for display
*/
export const formatType = (type: string): string => {
return typeLabels[type] || type
return typeLabels[type] ?? humaniseType(type)
}

/**
Expand Down
Loading
Loading