Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Consolidate Patrol activity into summary shell

rcourtmanf53f8a74101d
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index b79bcd4605..07a90376e2 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -228,6 +228,9 @@ Own canonical runtime payload shapes between backend and frontend.
and the split Patrol trigger settings contract, so `patrol_alert_triggers_enabled` and `patrol_anomaly_triggers_enabled` are the canonical AI settings fields while legacy `patrol_event_triggers_enabled` remains a compatibility aggregate rather than the primary control surface
7. Keep Patrol summary payload consumers aligned on one assessment hierarchy: transport-driven Patrol summary surfaces may show supporting counts and outcomes, but the canonical assessment and verification states must remain singular and not be repeated as a second compact verdict strip
8. Keep Patrol verification and activity facts unified on one transport-backed secondary status area: when frontend consumers combine Patrol status payloads (`runtime_state`, `last_patrol_at`, `last_activity_at`, `trigger_status`) with run-history transport, the latest run result, activity mix, scoped-trigger state, and circuit-breaker context must read as one supporting explanation beneath the primary assessment instead of being re-expanded into a separate full-width status strip plus duplicate summary layers
+ and the main Patrol page composition boundary, so once that governed
+ secondary area exists inside the summary shell the same payloads must not
+ also drive a second page-level status strip elsewhere on the route
9. Treat Patrol summary supporting metrics as readouts, not reinterpretations: when frontend consumers derive cards such as active findings, criticals, warnings, or fixes from the canonical payloads, those cards must stay numeric and must not synthesize new assessment labels like `Issues detected` or verification labels like `Partial verification` beneath the primary summary contract
10. Treat active Patrol runtime transport as compatible with factual activity surfaces: when the runtime is currently running, frontend consumers may surface in-progress activity context, but they must not replace the activity strip with a second assessment verdict derived from runtime state alone
11. Treat Patrol recency as a singular transport-driven fact: once header metadata, verification copy, or the findings footer already present the governed Patrol timing context, frontend summary consumers must not derive an extra timing pill from the same payloads inside the primary summary card
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 7dabc31243..d464537c04 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -1233,6 +1233,10 @@ alongside the verification readout rather than as a second full-width band
above the findings workspace. If `PatrolStatusBar.tsx` is reused elsewhere, it
must stay a compact factual support surface and must not reintroduce a parallel
page-level verdict strip once the summary shell already owns that explanation.
+That same composition rule applies to `frontend-modern/src/features/patrol/PatrolIntelligenceWorkspace.tsx`:
+once the summary shell carries the operator-facing verification and activity
+story, the workspace should move directly into findings and run history instead
+of repeating that same runtime context through a second pre-tab status strip.
Shared primitive consumers that split status-dot tone and status-text tone
must now keep both values routed through the same exported presentation helper.
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 23d976208b..1a046f1cc2 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -251,22 +251,32 @@ The same hierarchy applies to investigation context. Correlations, recent
changes, and policy posture are secondary evidence for deeper investigation, so
the `Investigation context` section belongs beneath the primary findings/history
workspace rather than inside the assessment card itself.
-The Patrol status bar should stay factual and operational within that same
-hierarchy. `frontend-modern/src/components/patrol/PatrolStatusBar.tsx` is a
-recent-activity strip, not a second health verdict: when Patrol is active it
-should report recent run activity, run kind, latest run result, and run-count
-context instead of emitting another green/amber all-clear headline that can
-drift from the governed assessment summary above it.
-That same activity strip should explain noisy Patrol behavior concretely. When
-same-day history shows a mix of full sweeps, verification checks, and scoped
-alert- or anomaly-triggered patrols, the strip should expose a compact
-breakdown of those run categories instead of leaving operators to infer why
-Patrol looked busy from an undifferentiated run count alone.
+That same operational context belongs inside the same secondary status area as
+verification, not as a separate full-width strip that competes with the
+findings workspace. `frontend-modern/src/features/patrol/PatrolIntelligenceSummary.tsx`
+plus the shared `frontend-modern/src/utils/patrolRunPresentation.ts` helpers
+should carry the latest run kind/result, recent activity mix, scoped-trigger
+state, and any circuit-breaker warning as factual support beneath the primary
+assessment instead of letting Patrol explain itself through multiple parallel
+status bands.
+That same secondary area should simplify by consolidation rather than
+deletion. Patrol should keep meaningful run and trigger facts visible, but it
+should stop repeating the same runtime story as a summary card, a metric row,
+and a separate status strip all at once.
+If `frontend-modern/src/components/patrol/PatrolStatusBar.tsx` is reused in a
+compact context elsewhere, it must stay factual and operational within that
+same hierarchy rather than introducing a second Patrol verdict label.
+That same activity explanation should handle noisy Patrol behavior concretely.
+When same-day history shows a mix of full sweeps, verification checks, and
+scoped alert- or anomaly-triggered patrols, the verification/activity surface
+should expose a compact breakdown of those run categories instead of leaving
+operators to infer why Patrol looked busy from an undifferentiated run count
+alone.
The same operational layer should also surface scoped-trigger state directly.
If Patrol has queued scoped work, is in busy mode, or has one scoped trigger
-source disabled, the status bar should state that as factual runtime context
-instead of forcing operators to cross-reference hidden settings or infer it
-from missing runs.
+source disabled, the governed summary should state that as factual runtime
+context instead of forcing operators to cross-reference hidden settings or
+infer it from missing runs.
That recent-activity copy also has to remain intelligible in compact or
plain-text renders: the latest-run segment must keep an explicit textual
separator between run kind and result, so degraded entries read as
diff --git a/frontend-modern/src/components/patrol/PatrolStatusBar.tsx b/frontend-modern/src/components/patrol/PatrolStatusBar.tsx
index 31f971d6b1..b9b9d99d5a 100644
--- a/frontend-modern/src/components/patrol/PatrolStatusBar.tsx
+++ b/frontend-modern/src/components/patrol/PatrolStatusBar.tsx
@@ -18,6 +18,7 @@ import { formatTriggerReason } from '@/utils/patrolFormat';
import {
formatPatrolActivityBreakdown,
getPatrolActivityBreakdown,
+ getPatrolTriggerStatusSummary,
getPatrolRunKindLabel,
getPatrolRunStatusPresentation,
} from '@/utils/patrolRunPresentation';
@@ -96,18 +97,7 @@ export const PatrolStatusBar: Component<PatrolStatusBarProps> = (props) => {
);
});
const showRunInProgress = createMemo(() => props.runtimeState === 'running');
- const triggerStatusSummary = createMemo(() => {
- const status = props.triggerStatus;
- if (!status) return '';
-
- const notes: string[] = [];
- if (status.pending_triggers > 0) notes.push(`${status.pending_triggers} queued`);
- if (status.is_busy_mode) notes.push('busy mode');
- if (!status.alert_triggers_enabled) notes.push('alerts off');
- if (!status.anomaly_triggers_enabled) notes.push('anomalies off');
- if (notes.length === 0) return '';
- return `Scoped triggers: ${notes.join(' · ')}`;
- });
+ const triggerStatusSummary = createMemo(() => getPatrolTriggerStatusSummary(props.triggerStatus));
const resolvedStats = createMemo(() => (!runs.loading ? stats() : null));
return (
@@ -227,7 +217,7 @@ export const PatrolStatusBar: Component<PatrolStatusBarProps> = (props) => {
<Show when={triggerStatusSummary()}>
<span class="hidden sm:inline text-slate-300 ">|</span>
- <span class="text-xs text-muted">{triggerStatusSummary()}</span>
+ <span class="text-xs text-muted">Scoped triggers: {triggerStatusSummary()}</span>
</Show>
</div>
</div>
diff --git a/frontend-modern/src/features/patrol/PatrolIntelligenceSummary.tsx b/frontend-modern/src/features/patrol/PatrolIntelligenceSummary.tsx
index 83e058f640..269c65e619 100644
--- a/frontend-modern/src/features/patrol/PatrolIntelligenceSummary.tsx
+++ b/frontend-modern/src/features/patrol/PatrolIntelligenceSummary.tsx
@@ -1,4 +1,4 @@
-import { createMemo, Show } from 'solid-js';
+import { createMemo, For, Show } from 'solid-js';
import ActivityIcon from 'lucide-solid/icons/activity';
import ShieldAlertIcon from 'lucide-solid/icons/shield-alert';
import CheckCircleIcon from 'lucide-solid/icons/check-circle';
@@ -10,10 +10,14 @@ import {
getPatrolAssessmentPresentation,
getPatrolRecencyPresentation,
getPatrolScoreChipLabel,
- getPatrolSummaryMetricState,
getPatrolVerificationPresentation,
getPatrolSummaryPresentation,
+ getPatrolSummaryMetricState,
} from '@/utils/patrolSummaryPresentation';
+import {
+ getPatrolLatestRunPresentation,
+ getPatrolTriggerStatusSummary,
+} from '@/utils/patrolRunPresentation';
import { getPatrolRuntimePresentation } from '@/utils/patrolRuntimePresentation';
import { formatRelativeTime } from '@/utils/format';
import type { PatrolIntelligenceState } from './usePatrolIntelligenceState';
@@ -21,9 +25,6 @@ import type { PatrolIntelligenceState } from './usePatrolIntelligenceState';
export function PatrolIntelligenceSummary(props: { state: PatrolIntelligenceState }) {
const state = props.state;
const summaryStats = createMemo(() => state.summaryStats());
- const criticalSummaryPresentation = createMemo(() =>
- getPatrolSummaryPresentation('critical', summaryStats().criticalFindings > 0),
- );
const metricState = createMemo(() =>
getPatrolSummaryMetricState({
activeFindings: state.activePatrolFindings(),
@@ -78,6 +79,28 @@ export function PatrolIntelligenceSummary(props: { state: PatrolIntelligenceStat
const fixedSummaryPresentation = createMemo(() =>
getPatrolSummaryPresentation('success', summaryStats().fixedCount > 0),
);
+ const latestRun = createMemo(() => getPatrolLatestRunPresentation(state.patrolRunHistory() ?? []));
+ const triggerSummary = createMemo(() =>
+ getPatrolTriggerStatusSummary(state.patrolStatus()?.trigger_status),
+ );
+ const circuitBreakerPresentation = createMemo(() => {
+ const circuitBreaker = state.circuitBreakerStatus();
+ if (!circuitBreaker || circuitBreaker.state === 'closed') {
+ return undefined;
+ }
+
+ if (circuitBreaker.state === 'open') {
+ return {
+ message: `AI circuit breaker tripped after ${circuitBreaker.consecutive_failures} consecutive failures.`,
+ toneClass: 'text-red-600 dark:text-red-400',
+ };
+ }
+
+ return {
+ message: 'AI circuit breaker recovering; the next Patrol run is a live test.',
+ toneClass: 'text-amber-600 dark:text-amber-400',
+ };
+ });
const scoreChipLabel = createMemo(() =>
getPatrolScoreChipLabel({
overallHealth: state.intelligenceSummary()?.overall_health,
@@ -89,6 +112,59 @@ export function PatrolIntelligenceSummary(props: { state: PatrolIntelligenceStat
activeFindings: state.activePatrolFindings(),
}),
);
+ const hasAttentionMetrics = createMemo(
+ () => metricState().primaryValue > 0 || metricState().secondaryValue > 0,
+ );
+ const visibleMetrics = createMemo(() => {
+ const metrics: Array<{
+ icon: typeof ActivityIcon;
+ key: string;
+ label: string;
+ presentation: ReturnType<typeof getPatrolSummaryPresentation>;
+ value: number;
+ }> = [];
+
+ if (metricState().primaryValue > 0) {
+ metrics.push({
+ icon:
+ summaryStats().criticalFindings > 0
+ ? ShieldAlertIcon
+ : summaryStats().totalActive > 0
+ ? AlertTriangleIcon
+ : ActivityIcon,
+ key: 'primary',
+ label: metricState().primaryLabel,
+ presentation: activeFindingsSummaryPresentation(),
+ value: metricState().primaryValue,
+ });
+ }
+
+ if (
+ metricState().secondaryValue > 0 &&
+ (metricState().secondaryLabel === 'Runtime issues' ||
+ metricState().secondaryValue !== metricState().primaryValue)
+ ) {
+ metrics.push({
+ icon: AlertCircleIcon,
+ key: 'secondary',
+ label: metricState().secondaryLabel,
+ presentation: warningSummaryPresentation(),
+ value: metricState().secondaryValue,
+ });
+ }
+
+ if (metricState().fixedValue > 0 && hasAttentionMetrics()) {
+ metrics.push({
+ icon: CheckCircleIcon,
+ key: 'fixed',
+ label: metricState().fixedLabel,
+ presentation: fixedSummaryPresentation(),
+ value: metricState().fixedValue,
+ });
+ }
+
+ return metrics;
+ });
const renderAssessmentIcon = () => {
const iconClass = `w-5 h-5 ${assessmentShellPresentation().iconClass}`;
@@ -195,29 +271,91 @@ export function PatrolIntelligenceSummary(props: { state: PatrolIntelligenceStat
</div>
</div>
- <div class="mt-5 rounded-md border border-border-subtle bg-surface-alt/60 p-3">
- <p class="text-xs font-semibold uppercase tracking-[0.16em] text-muted">
- Verification
- </p>
- <p class="mt-1 text-sm font-medium text-base-content">
- {verification().title}
- <Show when={verification().lastFullRunAt}>
- <span class="text-muted">
- {' '}
- ·{' '}
- {formatRelativeTime(verification().lastFullRunAt!, {
- compact: true,
- emptyText: 'never',
- })}
- </span>
- </Show>
- </p>
- <p class="mt-1 text-sm text-muted">{verification().description}</p>
- <Show when={verification().activityMixLabel}>
- <p class="mt-2 text-xs font-medium text-base-content">
- Recent activity mix: {verification().activityMixLabel}
- </p>
- </Show>
+ <div class="mt-5 overflow-hidden rounded-md border border-border-subtle bg-surface-alt/60">
+ <div class="grid divide-y divide-border-subtle lg:grid-cols-[minmax(0,1.35fr)_minmax(0,1fr)] lg:divide-x lg:divide-y-0">
+ <div class="p-3">
+ <p class="text-xs font-semibold uppercase tracking-[0.16em] text-muted">
+ Verification
+ </p>
+ <p class="mt-1 text-sm font-medium text-base-content">
+ {verification().title}
+ <Show when={verification().lastFullRunAt}>
+ <span class="text-muted">
+ {' '}
+ ·{' '}
+ {formatRelativeTime(verification().lastFullRunAt!, {
+ compact: true,
+ emptyText: 'never',
+ })}
+ </span>
+ </Show>
+ </p>
+ <p class="mt-1 text-sm text-muted">{verification().description}</p>
+ <Show when={verification().activityMixLabel}>
+ <p class="mt-2 text-xs font-medium text-base-content">
+ Recent activity mix: {verification().activityMixLabel}
+ </p>
+ </Show>
+ </div>
+
+ <div class="p-3">
+ <p class="text-xs font-semibold uppercase tracking-[0.16em] text-muted">
+ Activity
+ </p>
+ <Show
+ when={latestRun()}
+ fallback={
+ <p class="mt-1 text-sm text-muted">
+ Patrol has not completed recent activity yet.
+ </p>
+ }
+ >
+ {(latest) => (
+ <>
+ <div class="mt-1 flex flex-wrap items-center gap-2 text-sm">
+ <span class="font-medium text-base-content">{latest().kindLabel}</span>
+ <span
+ class={`inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium ${latest().status.badgeClass}`}
+ >
+ {latest().status.label}
+ </span>
+ <Show when={latest().timestamp}>
+ <span class="text-muted">
+ {formatRelativeTime(latest().timestamp!, {
+ compact: true,
+ emptyText: 'never',
+ })}
+ </span>
+ </Show>
+ </div>
+ <Show when={latest().coverageSummary}>
+ <p class="mt-1 text-sm text-muted">{latest().coverageSummary}</p>
+ </Show>
+ <Show when={!latest().findingsSnapshotAvailable}>
+ <p class="mt-1 text-xs text-muted">
+ Findings snapshot unavailable for this run.
+ </p>
+ </Show>
+ </>
+ )}
+ </Show>
+
+ <Show when={triggerSummary()}>
+ <p class="mt-3 text-sm text-muted">
+ <span class="font-medium text-base-content">Trigger mode:</span>{' '}
+ {triggerSummary()}
+ </p>
+ </Show>
+
+ <Show when={circuitBreakerPresentation()}>
+ {(circuitBreaker) => (
+ <p class={`mt-3 text-sm ${circuitBreaker().toneClass}`}>
+ {circuitBreaker().message}
+ </p>
+ )}
+ </Show>
+ </div>
+ </div>
</div>
</div>
</section>
@@ -225,91 +363,30 @@ export function PatrolIntelligenceSummary(props: { state: PatrolIntelligenceStat
</Show>
</Show>
- <Show when={!showRuntimeSummary() && state.intelligenceSummary()}>
- <div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3">
- <div class="bg-surface rounded-md border border-border p-3">
- <div class="flex items-center gap-2">
- <div
- class={`p-1.5 rounded-md border ${activeFindingsSummaryPresentation().iconContainerClass}`}
- >
- <Show
- when={summaryStats().criticalFindings > 0}
- fallback={
- <Show
- when={summaryStats().totalActive > 0}
- fallback={
- <ActivityIcon
- class={`w-4 h-4 ${activeFindingsSummaryPresentation().iconClass}`}
- />
- }
+ <Show when={!showRuntimeSummary() && state.intelligenceSummary() && visibleMetrics().length > 0}>
+ <div class="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3">
+ <For each={visibleMetrics()}>
+ {(metric) => {
+ const Icon = metric.icon;
+ return (
+ <div class="rounded-md border border-border-subtle bg-surface p-3">
+ <div class="flex items-center gap-2">
+ <div
+ class={`rounded-md border p-1.5 ${metric.presentation.iconContainerClass}`}
>
- <AlertTriangleIcon
- class={`w-4 h-4 ${activeFindingsSummaryPresentation().iconClass}`}
- />
- </Show>
- }
- >
- <ShieldAlertIcon
- class={`w-4 h-4 ${activeFindingsSummaryPresentation().iconClass}`}
- />
- </Show>
- </div>
- <div>
- <p class="text-xs text-muted">{metricState().primaryLabel}</p>
- <p class={`text-lg font-bold ${activeFindingsSummaryPresentation().valueClass}`}>
- {metricState().primaryValue}
- </p>
- </div>
- </div>
- </div>
-
- <div class="bg-surface rounded-md border border-border p-3">
- <div class="flex items-center gap-2">
- <div
- class={`p-1.5 rounded-md border ${warningSummaryPresentation().iconContainerClass}`}
- >
- <ActivityIcon class={`w-4 h-4 ${warningSummaryPresentation().iconClass}`} />
- </div>
- <div>
- <p class="text-xs text-muted">{metricState().secondaryLabel}</p>
- <p class={`text-lg font-bold ${warningSummaryPresentation().valueClass}`}>
- {metricState().secondaryValue}
- </p>
- </div>
- </div>
- </div>
-
- <div class="bg-surface rounded-md border border-border p-3">
- <div class="flex items-center gap-2">
- <div
- class={`p-1.5 rounded-md border ${criticalSummaryPresentation().iconContainerClass}`}
- >
- <ShieldAlertIcon class={`w-4 h-4 ${criticalSummaryPresentation().iconClass}`} />
- </div>
- <div>
- <p class="text-xs text-muted">{metricState().criticalLabel}</p>
- <p class={`text-lg font-bold ${criticalSummaryPresentation().valueClass}`}>
- {metricState().criticalValue}
- </p>
- </div>
- </div>
- </div>
-
- <div class="bg-surface rounded-md border border-border p-3">
- <div class="flex items-center gap-2">
- <div
- class={`p-1.5 rounded-md border ${fixedSummaryPresentation().iconContainerClass}`}
- >
- <CheckCircleIcon class={`w-4 h-4 ${fixedSummaryPresentation().iconClass}`} />
- </div>
- <div>
- <p class="text-xs text-muted">{metricState().fixedLabel}</p>
- <p class={`text-lg font-bold ${fixedSummaryPresentation().valueClass}`}>
- {metricState().fixedValue}
- </p>
- </div>
- </div>
- </div>
+ <Icon class={`h-4 w-4 ${metric.presentation.iconClass}`} />
+ </div>
+ <div>
+ <p class="text-xs text-muted">{metric.label}</p>
+ <p class={`text-lg font-bold ${metric.presentation.valueClass}`}>
+ {metric.value}
+ </p>
+ </div>
+ </div>
+ </div>
+ );
+ }}
+ </For>
</div>
</Show>
</>
diff --git a/frontend-modern/src/features/patrol/PatrolIntelligenceWorkspace.tsx b/frontend-modern/src/features/patrol/PatrolIntelligenceWorkspace.tsx
index 2327e8ee96..592de23246 100644
--- a/frontend-modern/src/features/patrol/PatrolIntelligenceWorkspace.tsx
+++ b/frontend-modern/src/features/patrol/PatrolIntelligenceWorkspace.tsx
@@ -1,6 +1,6 @@
import { Show } from 'solid-js';
import { FindingsPanel } from '@/components/AI/FindingsPanel';
-import { ApprovalBanner, PatrolStatusBar, RunHistoryPanel } from '@/components/patrol';
+import { ApprovalBanner, RunHistoryPanel } from '@/components/patrol';
import { getPatrolFindingsBadgePresentation } from '@/utils/aiFindingPresentation';
import { formatRelativeTime } from '@/utils/format';
import { formatTriggerReason } from '@/utils/patrolFormat';
@@ -32,14 +32,6 @@ export function PatrolIntelligenceWorkspace(props: { state: PatrolIntelligenceSt
}}
/>
- <PatrolStatusBar
- enabled={state.patrolEnabledLocal()}
- refreshTrigger={state.activityRefreshTrigger()}
- runtimeState={state.runtimeState()}
- blockedReason={state.blockedReason()}
- triggerStatus={state.patrolStatus()?.trigger_status}
- />
-
<div class="flex items-center gap-1 border-b border-border">
<button
type="button"
diff --git a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
index 8c913c7fb8..10910dec53 100644
--- a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
+++ b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
@@ -481,6 +481,7 @@ export function usePatrolIntelligenceState() {
});
const intelligenceSummary = createMemo(() => aiIntelligenceStore.intelligenceSummary);
+ const circuitBreakerStatus = createMemo(() => aiIntelligenceStore.circuitBreakerStatus);
const policyPosture = createMemo(() => intelligenceSummary()?.policy_posture);
const investigationContext = createMemo(() =>
buildPatrolInvestigationContextSummary({
@@ -715,6 +716,7 @@ export function usePatrolIntelligenceState() {
blockedReason,
canStartTrial,
canTriggerPatrol,
+ circuitBreakerStatus,
correlationTotal,
correlations,
clearScrollToFindingTimer,
diff --git a/frontend-modern/src/utils/__tests__/patrolRunPresentation.test.ts b/frontend-modern/src/utils/__tests__/patrolRunPresentation.test.ts
index 2d348c51ee..01fa0ede6d 100644
--- a/frontend-modern/src/utils/__tests__/patrolRunPresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/patrolRunPresentation.test.ts
@@ -3,10 +3,12 @@ import type { PatrolRunRecord } from '@/api/patrol';
import {
formatPatrolActivityBreakdown,
getPatrolActivityBreakdown,
+ getPatrolLatestRunPresentation,
getPatrolRunKindLabel,
getPatrolRunCoverageSummary,
getPatrolRunResourcesHeading,
getPatrolRunStatusPresentation,
+ getPatrolTriggerStatusSummary,
isPatrolRunHealthy,
getRunHistoryLoadingState,
getRunHistorySelectionHint,
@@ -91,6 +93,67 @@ describe('patrolRunPresentation', () => {
expect(getPatrolRunKindLabel('unexpected')).toBe('Patrol run');
});
+ it('derives the latest run presentation from recent completed history', () => {
+ expect(
+ getPatrolLatestRunPresentation([
+ {
+ id: 'run-latest',
+ started_at: '2026-03-12T10:00:00Z',
+ completed_at: '2026-03-12T10:01:00Z',
+ duration_ms: 60000,
+ type: 'scoped',
+ trigger_reason: 'alert_fired',
+ scope_resource_ids: ['seed-resource'],
+ effective_scope_resource_ids: ['expanded-a', 'expanded-b'],
+ resources_checked: 1,
+ nodes_checked: 0,
+ guests_checked: 0,
+ docker_checked: 0,
+ storage_checked: 0,
+ hosts_checked: 0,
+ truenas_checked: 0,
+ pbs_checked: 0,
+ pmg_checked: 0,
+ kubernetes_checked: 0,
+ new_findings: 0,
+ existing_findings: 0,
+ rejected_findings: 0,
+ resolved_findings: 0,
+ auto_fix_count: 0,
+ findings_summary: 'ok',
+ error_count: 1,
+ status: 'healthy',
+ triage_flags: 0,
+ tool_call_count: 0,
+ finding_ids: undefined,
+ },
+ ] satisfies PatrolRunRecord[]),
+ ).toEqual({
+ coverageSummary: 'Checked 1 of 2 scoped resources',
+ findingsSnapshotAvailable: false,
+ kindLabel: 'Scoped run',
+ status: {
+ badgeClass: 'bg-red-100 text-red-700 dark:bg-red-900 dark:text-red-300',
+ label: 'error',
+ },
+ timestamp: '2026-03-12T10:01:00Z',
+ });
+ });
+
+ it('summarizes scoped trigger state for compact activity surfaces', () => {
+ expect(
+ getPatrolTriggerStatusSummary({
+ running: true,
+ pending_triggers: 4,
+ current_interval_ms: 300000,
+ recent_events: 6,
+ is_busy_mode: true,
+ alert_triggers_enabled: true,
+ anomaly_triggers_enabled: false,
+ }),
+ ).toBe('4 queued · busy mode · anomalies off');
+ });
+
it('expresses scoped run coverage against the effective scope', () => {
expect(getPatrolRunCoverageSummary(scopedCoverageRun)).toBe('Checked 1 of 2 scoped resources');
expect(getPatrolRunResourcesHeading(scopedCoverageRun)).toBe(
diff --git a/frontend-modern/src/utils/patrolRunPresentation.ts b/frontend-modern/src/utils/patrolRunPresentation.ts
index f2e3163ce3..5d17a81039 100644
--- a/frontend-modern/src/utils/patrolRunPresentation.ts
+++ b/frontend-modern/src/utils/patrolRunPresentation.ts
@@ -1,4 +1,4 @@
-import type { PatrolRunRecord, PatrolRunStatus } from '@/api/patrol';
+import type { PatrolRunRecord, PatrolRunStatus, PatrolTriggerStatus } from '@/api/patrol';
import { formatIdentifierLabel } from '@/utils/textPresentation';
import { getCanonicalScopeResourceIds } from '@/utils/patrolFormat';
@@ -7,6 +7,14 @@ export interface PatrolRunStatusPresentation {
label: string;
}
+export interface PatrolLatestRunPresentation {
+ coverageSummary: string;
+ findingsSnapshotAvailable: boolean;
+ kindLabel: string;
+ status: PatrolRunStatusPresentation;
+ timestamp?: string;
+}
+
export interface PatrolActivityBreakdown {
totalRuns: number;
fullPatrols: number;
@@ -126,6 +134,45 @@ export function getPatrolRunKindLabel(type: string | undefined): string {
}
}
+export function getPatrolLatestRunPresentation(
+ runs: PatrolRunRecord[],
+): PatrolLatestRunPresentation | undefined {
+ const latestRun = runs.find((run) => Boolean(run.completed_at?.trim() || run.started_at?.trim()));
+ if (!latestRun) {
+ return undefined;
+ }
+
+ const findingsSnapshotAvailable = latestRun.finding_ids !== undefined;
+
+ return {
+ coverageSummary: getPatrolRunCoverageSummary(latestRun),
+ findingsSnapshotAvailable,
+ kindLabel: getPatrolRunKindLabel(latestRun.type),
+ status: getPatrolRunStatusPresentation(
+ latestRun.status ?? 'unknown',
+ latestRun.error_count ?? 0,
+ findingsSnapshotAvailable,
+ ),
+ timestamp: latestRun.completed_at || latestRun.started_at,
+ };
+}
+
+export function getPatrolTriggerStatusSummary(
+ status: PatrolTriggerStatus | undefined,
+): string | undefined {
+ if (!status) {
+ return undefined;
+ }
+
+ const notes: string[] = [];
+ if (status.pending_triggers > 0) notes.push(`${status.pending_triggers} queued`);
+ if (status.is_busy_mode) notes.push('busy mode');
+ if (!status.alert_triggers_enabled) notes.push('alerts off');
+ if (!status.anomaly_triggers_enabled) notes.push('anomalies off');
+
+ return notes.length > 0 ? notes.join(' · ') : undefined;
+}
+
function isSameLocalDay(timestamp: string | undefined, referenceDate: Date): boolean {
if (!timestamp) return false;
const value = new Date(timestamp);
diff --git a/tests/integration/tests/18-patrol-runtime-state.spec.ts b/tests/integration/tests/18-patrol-runtime-state.spec.ts
index 6a867aa0f4..85ce407920 100644
--- a/tests/integration/tests/18-patrol-runtime-state.spec.ts
+++ b/tests/integration/tests/18-patrol-runtime-state.spec.ts
@@ -498,7 +498,7 @@ test.describe("Patrol runtime-state browser contract", () => {
await expect(page.getByText("Health A · 100/100")).toHaveCount(0);
});
- test("surfaces scoped trigger breakdown and split trigger controls on the Patrol page", async ({
+ test("surfaces scoped trigger context inside the summary and split trigger controls on the Patrol page", async ({
page,
}, testInfo) => {
test.skip(
@@ -515,14 +515,14 @@ test.describe("Patrol runtime-state browser contract", () => {
page.getByText(
"Breakdown: 1 full, 1 alert-triggered, 1 anomaly-triggered",
),
- ).toBeVisible();
+ ).toHaveCount(0);
await expect(
page.getByText(
"Recent activity mix: 1 full, 1 alert-triggered, 1 anomaly-triggered",
),
).toBeVisible();
await expect(
- page.getByText("Scoped triggers: 4 queued · busy mode · anomalies off"),
+ page.getByText("Trigger mode: 4 queued · busy mode · anomalies off"),
).toBeVisible();
await page.getByRole("button", { name: "Configure Patrol" }).click();