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.

Attach alert briefings to Assistant handoffs

rcourtmanaf067372b6bd
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index a9579e052c..413a0541a5 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -285,7 +285,8 @@ runtime cost control, and shared AI transport surfaces.
When the drawer renders a request-local approval-required banner for a
scoped handoff, the banner must derive its subject from the attached
briefing or structured finding context, so Patrol approval/finding handoffs
- are named as Patrol handoffs rather than generic dashboard briefs.
+ and alert-investigation handoffs are named by their source rather than as
+ generic dashboard briefs.
## Current State
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index 46a92d5f9c..4e88a0ed32 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -80,6 +80,7 @@ operator-facing alert routing behavior for live runtime alerts.
58. `internal/alerts/active_lifecycle.go`
59. `internal/alerts/active_cleanup.go`
60. `frontend-modern/src/components/Alerts/InvestigateAlertButton.tsx`
+61. `frontend-modern/src/components/Alerts/alertAssistantHandoffModel.ts`
## Shared Boundaries
@@ -104,10 +105,12 @@ operator-facing alert routing behavior for live runtime alerts.
consume the same configured alert thresholds and override identity chain as
the alert runtime instead of hard-coded per-surface thresholds.
7. Add or change unlocked Pulse Assistant alert investigation handoffs through
- `frontend-modern/src/components/Alerts/InvestigateAlertButton.tsx`; these
- handoffs must preserve alert context, force request-scoped approval mode,
- and must not instruct the Assistant to execute diagnostics or remediation
- without operator approval.
+ `frontend-modern/src/components/Alerts/InvestigateAlertButton.tsx` and
+ `frontend-modern/src/components/Alerts/alertAssistantHandoffModel.ts`;
+ these handoffs must preserve alert context, force request-scoped approval
+ mode, attach a visible alert-owned Assistant drawer briefing, and must not
+ instruct the Assistant to execute diagnostics or remediation without operator
+ approval.
## Forbidden Paths
@@ -363,7 +366,11 @@ Unlocked alert-investigation Assistant handoffs are contextual explanation and
triage entries, not autonomous execution grants. `InvestigateAlertButton.tsx`
must pass `autonomousMode: false` when it opens Pulse Assistant, and the seeded
prompt may ask for root-cause analysis, metrics checks, and remediation advice
-only if command or change execution remains explicitly approval-bound.
+only if command or change execution remains explicitly approval-bound. The
+visible drawer briefing for that same handoff is Alerts-owned presentation
+context: alert identifier, severity, metric, resource, threshold, duration,
+node label, and message may be shown, while raw diagnostic or remediation
+commands remain outside the handoff.
Alert-adjacent shared helpers also inherit the runtime-versus-commercial split
now carried by the shared licensing stores. Alert pages may consume runtime
feature truth from `frontend-modern/src/stores/license.ts`, but any
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index fa1b845143..93ccf7827c 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -821,8 +821,9 @@ frontend primitive boundary.
`AIChatContextBriefing`; raw approval commands remain owned by the governed
approval/remediation panels. The shared approval-required drawer banner must
derive its subject from that briefing or structured finding context, so
- Patrol handoffs render as Patrol handoffs or Patrol findings rather than
- generic dashboard briefs. Patrol approval-row Assistant prompts must
+ Patrol handoffs render as Patrol handoffs or Patrol findings, and alert
+ handoffs render as alert investigations, rather than generic dashboard
+ briefs. Patrol approval-row Assistant prompts must
follow that same drawer primitive contract: safe approval metadata may enter
the prompt and context, but raw command text stays out and the scoped
request must pass `autonomousMode:false` instead of changing the user's
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
index 5a37b2170a..bfb09c4ca1 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -75,22 +75,27 @@ const {
const mockAiChatStore = {
isOpenSignal: vi.fn(() => true),
context: {
- initialPrompt: undefined as string | undefined,
- findingId: undefined as string | undefined,
- autonomousMode: undefined as boolean | undefined,
- briefing: undefined as
- | {
- sourceLabel: string;
- title: string;
- subject?: string;
- statusLabel?: string;
- detailLines?: string[];
- evidence?: string[];
- actionLabel?: string;
- commandSummary?: string;
- safetyNote?: string;
- }
- | undefined,
+ initialPrompt: undefined,
+ findingId: undefined,
+ autonomousMode: undefined,
+ context: undefined,
+ briefing: undefined,
+ } as {
+ initialPrompt?: string;
+ findingId?: string;
+ autonomousMode?: boolean;
+ context?: Record<string, unknown>;
+ briefing?: {
+ sourceLabel: string;
+ title: string;
+ subject?: string;
+ statusLabel?: string;
+ detailLines?: string[];
+ evidence?: string[];
+ actionLabel?: string;
+ commandSummary?: string;
+ safetyNote?: string;
+ };
},
clearInitialPrompt: vi.fn(),
clearFindingId: vi.fn(),
@@ -1052,6 +1057,38 @@ describe('AIChat', () => {
screen.queryByText(/Approval required for this dashboard brief/),
).not.toBeInTheDocument();
});
+
+ it('names scoped alert handoffs in the approval banner', async () => {
+ mockAIAPI.getSettings.mockResolvedValue({
+ model: 'gpt-4',
+ chat_model: '',
+ control_level: 'autonomous',
+ autonomous_mode: true,
+ discovery_enabled: true,
+ });
+ mockAiChatStore.context = {
+ initialPrompt: undefined,
+ autonomousMode: false,
+ briefing: {
+ sourceLabel: 'Pulse Alerts',
+ title: 'Alert investigation attached',
+ },
+ context: {
+ alertIdentifier: 'alert-1',
+ },
+ };
+
+ renderChat();
+
+ await waitFor(() => {
+ expect(
+ screen.getByText(/Approval required for this alert investigation/),
+ ).toBeInTheDocument();
+ });
+ expect(
+ screen.queryByText(/Approval required for this dashboard brief/),
+ ).not.toBeInTheDocument();
+ });
});
// ── Discovery hint ───────────────────────────────────────────────────
diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsx
index dbb9239ef6..d7224141a3 100644
--- a/frontend-modern/src/components/AI/Chat/index.tsx
+++ b/frontend-modern/src/components/AI/Chat/index.tsx
@@ -317,6 +317,9 @@ export const AIChat: Component<AIChatProps> = (props) => {
const scopedApprovalHandoffLabel = createMemo(() => {
const source = contextBriefing()?.sourceLabel?.toLowerCase() || '';
if (source.includes('patrol')) return 'this Patrol handoff';
+ if (source.includes('alert') || aiChatStore.context.context?.alertIdentifier) {
+ return 'this alert investigation';
+ }
if (aiChatStore.context.findingId) return 'this Patrol finding';
return 'this dashboard brief';
});
diff --git a/frontend-modern/src/components/Alerts/InvestigateAlertButton.tsx b/frontend-modern/src/components/Alerts/InvestigateAlertButton.tsx
index ec4cc33a91..bf3798cdb4 100644
--- a/frontend-modern/src/components/Alerts/InvestigateAlertButton.tsx
+++ b/frontend-modern/src/components/Alerts/InvestigateAlertButton.tsx
@@ -2,11 +2,9 @@ import { Show, createSignal } from 'solid-js';
import { aiChatStore } from '@/stores/aiChat';
import type { Alert } from '@/types/api';
import { useUpgradeNavigation } from '@/components/shared/useUpgradeNavigation';
-import { getCanonicalAlertId } from '@/features/alerts/identity';
-import { formatAlertValue } from '@/utils/alertFormatters';
-import { resolveAlertTargetType } from '@/utils/alertTargetTypes';
import { getUpgradeActionDestination } from '@/stores/licenseCommercial';
import { presentationPolicyHidesUpgradePrompts } from '@/stores/sessionPresentationPolicy';
+import { buildAlertAssistantHandoff } from './alertAssistantHandoffModel';
interface InvestigateAlertButtonProps {
alert: Alert;
@@ -50,57 +48,14 @@ export function InvestigateAlertButton(props: InvestigateAlertButtonProps) {
return;
}
- // Calculate how long the alert has been active
- const startTime = new Date(props.alert.startTime);
- const now = new Date();
- const durationMs = now.getTime() - startTime.getTime();
- const durationMins = Math.floor(durationMs / 60000);
- const durationStr =
- durationMins < 60
- ? `${durationMins} min${durationMins !== 1 ? 's' : ''}`
- : `${Math.floor(durationMins / 60)}h ${durationMins % 60}m`;
-
- // Format a focused prompt for investigation
- const prompt = `Investigate this ${props.alert.level.toUpperCase()} alert:
-
-**Resource:** ${props.alert.resourceName}
-**Alert Type:** ${props.alert.type}
-**Current Value:** ${formatAlertValue(props.alert.value, props.alert.type)}
-**Threshold:** ${formatAlertValue(props.alert.threshold, props.alert.type)}
-**Duration:** ${durationStr}
-${props.alert.node ? `**Node:** ${props.alert.nodeDisplayName || props.alert.node}` : ''}
-
-Please:
-1. Identify the root cause
-2. Check related metrics
-3. Suggest specific remediation steps
-4. Ask for operator approval before running any diagnostic command or change`;
-
- const targetType = resolveAlertTargetType({
- alertType: props.alert.type,
+ const handoff = buildAlertAssistantHandoff({
+ alert: props.alert,
resourceType: props.resourceType,
- metadataResourceType:
- typeof props.alert.metadata?.resourceType === 'string'
- ? (props.alert.metadata.resourceType as string)
- : undefined,
- resourceId: props.alert.resourceId,
+ vmid: props.vmid,
});
// Open AI chat with this context and prompt
- aiChatStore.openWithPrompt(prompt, {
- targetType,
- targetId: props.alert.resourceId,
- autonomousMode: false,
- context: {
- alertIdentifier: getCanonicalAlertId(props.alert),
- alertType: props.alert.type,
- alertLevel: props.alert.level,
- alertMessage: props.alert.message,
- guestName: props.alert.resourceName,
- node: props.alert.node,
- vmid: props.vmid,
- },
- });
+ aiChatStore.openWithPrompt(handoff.prompt, handoff.context);
};
const sizeClasses = {
diff --git a/frontend-modern/src/components/Alerts/__tests__/InvestigateAlertButton.test.tsx b/frontend-modern/src/components/Alerts/__tests__/InvestigateAlertButton.test.tsx
index 43d9f19ad5..e8c6e5959b 100644
--- a/frontend-modern/src/components/Alerts/__tests__/InvestigateAlertButton.test.tsx
+++ b/frontend-modern/src/components/Alerts/__tests__/InvestigateAlertButton.test.tsx
@@ -15,30 +15,29 @@ const {
getUpgradeActionDestinationMock,
getUpgradeActionUrlOrFallbackMock,
presentationPolicyHidesUpgradePromptsMock,
-} =
- vi.hoisted(() => {
- const openWithPromptMock = vi.fn();
- const openUpgradeDestinationMock = vi.fn();
- const formatAlertValueMock = vi.fn((value?: number, _type?: string) =>
- value !== undefined ? `${value.toFixed(1)}%` : 'N/A',
- );
- const getUpgradeActionDestinationMock = vi.fn();
- const getUpgradeActionUrlOrFallbackMock = vi.fn();
- const presentationPolicyHidesUpgradePromptsMock = vi.fn();
- const mockAiChatStore = {
- enabled: true as boolean | null,
- openWithPrompt: (...args: unknown[]) => openWithPromptMock(...args),
- };
- return {
- openWithPromptMock,
- openUpgradeDestinationMock,
- formatAlertValueMock,
- mockAiChatStore,
- getUpgradeActionDestinationMock,
- getUpgradeActionUrlOrFallbackMock,
- presentationPolicyHidesUpgradePromptsMock,
- };
- });
+} = vi.hoisted(() => {
+ const openWithPromptMock = vi.fn();
+ const openUpgradeDestinationMock = vi.fn();
+ const formatAlertValueMock = vi.fn((value?: number, _type?: string) =>
+ value !== undefined ? `${value.toFixed(1)}%` : 'N/A',
+ );
+ const getUpgradeActionDestinationMock = vi.fn();
+ const getUpgradeActionUrlOrFallbackMock = vi.fn();
+ const presentationPolicyHidesUpgradePromptsMock = vi.fn();
+ const mockAiChatStore = {
+ enabled: true as boolean | null,
+ openWithPrompt: (...args: unknown[]) => openWithPromptMock(...args),
+ };
+ return {
+ openWithPromptMock,
+ openUpgradeDestinationMock,
+ formatAlertValueMock,
+ mockAiChatStore,
+ getUpgradeActionDestinationMock,
+ getUpgradeActionUrlOrFallbackMock,
+ presentationPolicyHidesUpgradePromptsMock,
+ };
+});
vi.mock('@/stores/aiChat', () => ({
aiChatStore: mockAiChatStore,
@@ -294,6 +293,19 @@ describe('InvestigateAlertButton', () => {
targetType: 'vm',
targetId: 'vm-101',
autonomousMode: false,
+ briefing: expect.objectContaining({
+ sourceLabel: 'Pulse Alerts',
+ title: 'Alert investigation attached',
+ subject: 'Warning cpu on test-vm',
+ statusLabel: expect.stringContaining('Warning alert'),
+ detailLines: expect.arrayContaining([
+ 'Current value 82.5%; threshold 80.0%',
+ 'Node: PVE Node 1',
+ 'Message: CPU usage is high',
+ ]),
+ actionLabel: 'Investigate alert alert-1',
+ safetyNote: 'Diagnostics and remediation require operator approval.',
+ }),
context: {
alertIdentifier: 'alert-1',
alertType: 'cpu',
@@ -316,8 +328,13 @@ describe('InvestigateAlertButton', () => {
];
expect(context.autonomousMode).toBe(false);
+ expect(context.briefing).toMatchObject({
+ sourceLabel: 'Pulse Alerts',
+ title: 'Alert investigation attached',
+ });
expect(prompt).toContain('Ask for operator approval before running any diagnostic command');
expect(prompt).not.toContain('Execute diagnostic commands if safe');
+ expect(JSON.stringify(context.briefing)).not.toContain('systemctl');
});
it('does not open the upgrade destination when unlocked', async () => {
diff --git a/frontend-modern/src/components/Alerts/__tests__/alertAssistantHandoffModel.test.ts b/frontend-modern/src/components/Alerts/__tests__/alertAssistantHandoffModel.test.ts
new file mode 100644
index 0000000000..8474c3ca5a
--- /dev/null
+++ b/frontend-modern/src/components/Alerts/__tests__/alertAssistantHandoffModel.test.ts
@@ -0,0 +1,78 @@
+import { describe, expect, it } from 'vitest';
+import type { Alert } from '@/types/api';
+import { buildAlertAssistantHandoff } from '../alertAssistantHandoffModel';
+
+function makeAlert(overrides: Partial<Alert> = {}): Alert {
+ return {
+ id: 'alert-1',
+ type: 'cpu',
+ level: 'warning',
+ resourceId: 'vm-101',
+ resourceName: 'app-vm',
+ node: 'pve1',
+ nodeDisplayName: 'PVE Node 1',
+ instance: '',
+ message: 'CPU usage is high',
+ value: 82.5,
+ threshold: 80,
+ startTime: '2026-05-07T10:00:00.000Z',
+ acknowledged: false,
+ ...overrides,
+ };
+}
+
+describe('alertAssistantHandoffModel', () => {
+ it('builds a visible approval-required alert handoff without command payloads', () => {
+ const handoff = buildAlertAssistantHandoff({
+ alert: makeAlert(),
+ now: new Date('2026-05-07T10:05:00.000Z'),
+ vmid: 101,
+ });
+
+ expect(handoff.prompt).toContain('Investigate this WARNING alert');
+ expect(handoff.prompt).toContain(
+ 'Ask for operator approval before running any diagnostic command',
+ );
+ expect(handoff.context).toMatchObject({
+ targetType: 'vm',
+ targetId: 'vm-101',
+ autonomousMode: false,
+ briefing: {
+ sourceLabel: 'Pulse Alerts',
+ title: 'Alert investigation attached',
+ subject: 'Warning cpu on app-vm',
+ statusLabel: 'Warning alert · Active 5 mins',
+ detailLines: [
+ 'Current value 82.5%; threshold 80.0%',
+ 'Node: PVE Node 1',
+ 'Message: CPU usage is high',
+ ],
+ actionLabel: 'Investigate alert alert-1',
+ safetyNote: 'Diagnostics and remediation require operator approval.',
+ },
+ context: {
+ alertIdentifier: 'alert-1',
+ alertType: 'cpu',
+ alertLevel: 'warning',
+ alertMessage: 'CPU usage is high',
+ guestName: 'app-vm',
+ node: 'pve1',
+ vmid: 101,
+ },
+ });
+ expect(JSON.stringify(handoff)).not.toContain('systemctl');
+ });
+
+ it('uses canonical target inference for alert resources', () => {
+ const handoff = buildAlertAssistantHandoff({
+ alert: makeAlert({
+ type: 'docker_cpu',
+ resourceId: 'container-1',
+ metadata: { resourceType: 'container' },
+ }),
+ now: new Date('2026-05-07T10:05:00.000Z'),
+ });
+
+ expect(handoff.context.targetType).toBe('app-container');
+ });
+});
diff --git a/frontend-modern/src/components/Alerts/alertAssistantHandoffModel.ts b/frontend-modern/src/components/Alerts/alertAssistantHandoffModel.ts
new file mode 100644
index 0000000000..4f76f3c345
--- /dev/null
+++ b/frontend-modern/src/components/Alerts/alertAssistantHandoffModel.ts
@@ -0,0 +1,105 @@
+import type { Alert } from '@/types/api';
+import type { AIChatContext } from '@/stores/aiChat';
+import { getCanonicalAlertId } from '@/features/alerts/identity';
+import { formatAlertValue } from '@/utils/alertFormatters';
+import { resolveAlertTargetType } from '@/utils/alertTargetTypes';
+
+interface BuildAlertAssistantHandoffInput {
+ alert: Alert;
+ resourceType?: string;
+ vmid?: number;
+ now?: Date;
+}
+
+interface AlertAssistantHandoff {
+ prompt: string;
+ context: Omit<AIChatContext, 'initialPrompt'>;
+}
+
+export function buildAlertAssistantHandoff({
+ alert,
+ resourceType,
+ vmid,
+ now = new Date(),
+}: BuildAlertAssistantHandoffInput): AlertAssistantHandoff {
+ const alertIdentifier = getCanonicalAlertId(alert);
+ const durationText = formatAlertDuration(alert.startTime, now);
+ const currentValue = formatAlertValue(alert.value, alert.type);
+ const thresholdValue = formatAlertValue(alert.threshold, alert.type);
+ const nodeLabel = alert.node ? alert.nodeDisplayName || alert.node : '';
+ const levelLabel = formatAlertLevel(alert.level);
+ const targetType = resolveAlertTargetType({
+ alertType: alert.type,
+ resourceType,
+ metadataResourceType:
+ typeof alert.metadata?.resourceType === 'string'
+ ? (alert.metadata.resourceType as string)
+ : undefined,
+ resourceId: alert.resourceId,
+ });
+
+ const prompt = `Investigate this ${alert.level.toUpperCase()} alert:
+
+**Resource:** ${alert.resourceName}
+**Alert Type:** ${alert.type}
+**Current Value:** ${currentValue}
+**Threshold:** ${thresholdValue}
+**Duration:** ${durationText}
+${nodeLabel ? `**Node:** ${nodeLabel}` : ''}
+
+Please:
+1. Identify the root cause
+2. Check related metrics
+3. Suggest specific remediation steps
+4. Ask for operator approval before running any diagnostic command or change`;
+
+ return {
+ prompt,
+ context: {
+ targetType,
+ targetId: alert.resourceId,
+ autonomousMode: false,
+ briefing: {
+ sourceLabel: 'Pulse Alerts',
+ title: 'Alert investigation attached',
+ subject: `${levelLabel} ${alert.type} on ${alert.resourceName}`,
+ statusLabel: `${levelLabel} alert · Active ${durationText}`,
+ detailLines: [
+ `Current value ${currentValue}; threshold ${thresholdValue}`,
+ nodeLabel ? `Node: ${nodeLabel}` : undefined,
+ alert.message ? `Message: ${alert.message}` : undefined,
+ ].filter((line): line is string => Boolean(line)),
+ actionLabel: `Investigate alert ${alertIdentifier}`,
+ safetyNote: 'Diagnostics and remediation require operator approval.',
+ },
+ context: {
+ alertIdentifier,
+ alertType: alert.type,
+ alertLevel: alert.level,
+ alertMessage: alert.message,
+ guestName: alert.resourceName,
+ node: alert.node,
+ vmid,
+ },
+ },
+ };
+}
+
+function formatAlertDuration(startTime: string, now: Date): string {
+ const startedAt = new Date(startTime).getTime();
+ const nowMs = now.getTime();
+ if (!Number.isFinite(startedAt) || !Number.isFinite(nowMs)) {
+ return 'unknown duration';
+ }
+
+ const durationMs = Math.max(0, nowMs - startedAt);
+ const durationMins = Math.floor(durationMs / 60000);
+ if (durationMins < 60) {
+ return `${durationMins} min${durationMins !== 1 ? 's' : ''}`;
+ }
+ return `${Math.floor(durationMins / 60)}h ${durationMins % 60}m`;
+}
+
+function formatAlertLevel(level: Alert['level']): string {
+ return level.charAt(0).toUpperCase() + level.slice(1);
+}