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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Share backend resource change presentation
rcourtman7f7b84e62182
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex ea9ade78d2..3e049dd264 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -163,6 +163,10 @@ The shared AI resource and infrastructure prompt contexts should also surfacethe same canonical recent changes section before any patrol-local fallback sothe model sees the same timeline entries that power the resource API andintelligence summary counts.+Those backend AI and Patrol change summaries should derive their canonical+labels and provenance fragments from+`internal/unifiedresources/change_presentation.go`, so the resource-model+semantics are shared before any surface-specific markdown styling is applied.The per-resource intelligence payload returned from`/api/ai/intelligence?resource_id=...` should also include the canonical`recent_changes` history so UI and API consumers can read the same timelinediff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.mdindex 87b0d3c046..3dbb0ceaf0 100644--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md@@ -88,3 +88,7 @@ The Patrol page and resource drawer now also share the canonical`frontend-modern/src/utils/resourceChangePresentation.ts` formatter sorecent-change kind and headline wording stays aligned wherever the canonicaltimeline is surfaced.+The backend Patrol and AI runtime summaries now also share+`internal/unifiedresources/change_presentation.go` for the canonical+change-kind and provenance mapping, so the same resource-model semantics+drive both the backend summaries and the frontend presentation helpers.diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex 2aa6dc45e7..31b5ef86de 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -92,6 +92,11 @@ hints.Those same relationship changes now summarize the actual edge(s) in `from` and`to`, so the canonical timeline keeps the graph transition readable withoutneeding the drawer to reconstruct an edge summary from raw endpoints.+The backend AI and Patrol context renderers now derive their canonical change+kind, source type, source adapter, actor, reason, and related-resource+fragments from `internal/unifiedresources/change_presentation.go`, so the+semantic mapping lives with the resource model instead of being duplicated in+lane-local prompt helpers.The change emitter now also classifies canonical restart changes for Dockerand Kubernetes resources when restart counters increase or uptime resets, sothe timeline can distinguish restarts from generic state transitions insteaddiff --git a/internal/ai/patrol_ai.go b/internal/ai/patrol_ai.goindex 0326d3d1ca..23c65c2587 100644--- a/internal/ai/patrol_ai.go+++ b/internal/ai/patrol_ai.go@@ -1691,12 +1691,13 @@ func (p *PatrolService) loadCanonicalRecentChanges(scopedSet map[string]bool, si}func patrolRecentChangeFromUnified(change unifiedresources.ResourceChange) memory.Change {+ presentation := unifiedresources.DescribeChange(change)return memory.Change{ResourceID: strings.TrimSpace(change.ResourceID),ResourceName: strings.TrimSpace(change.ResourceID),- ChangeType: memory.ChangeType(formatResourceChangeKindLabel(change.Kind)),+ ChangeType: memory.ChangeType(presentation.KindLabel),DetectedAt: patrolRecentChangeDetectedAt(change),- Description: patrolFormatCanonicalRecentChangeDescription(change),+ Description: patrolFormatCanonicalRecentChangeDescription(presentation),}}@@ -1710,41 +1711,41 @@ func patrolRecentChangeDetectedAt(change unifiedresources.ResourceChange) time.Treturn time.Now()}-func patrolFormatCanonicalRecentChangeDescription(change unifiedresources.ResourceChange) string {- parts := []string{formatResourceChangeKindLabel(change.Kind)}+func patrolFormatCanonicalRecentChangeDescription(presentation unifiedresources.ChangePresentation) string {+ parts := []string{presentation.KindLabel}- if from := strings.TrimSpace(change.From); from != "" || strings.TrimSpace(change.To) != "" {+ if from, to := strings.TrimSpace(presentation.From), strings.TrimSpace(presentation.To); from != "" || to != "" {switch {- case from != "" && strings.TrimSpace(change.To) != "":- parts = append(parts, fmt.Sprintf("%s -> %s", from, strings.TrimSpace(change.To)))+ case from != "" && to != "":+ parts = append(parts, fmt.Sprintf("%s -> %s", from, to))case from != "":parts = append(parts, fmt.Sprintf("from %s", from))default:- parts = append(parts, fmt.Sprintf("to %s", strings.TrimSpace(change.To)))+ parts = append(parts, fmt.Sprintf("to %s", to))}}- if sourceType := strings.TrimSpace(string(change.SourceType)); sourceType != "" {- if sourceAdapter := strings.TrimSpace(string(change.SourceAdapter)); sourceAdapter != "" {+ if sourceType := strings.TrimSpace(presentation.SourceType); sourceType != "" {+ if sourceAdapter := strings.TrimSpace(presentation.SourceAdapter); sourceAdapter != "" {parts = append(parts, fmt.Sprintf("source: %s via %s", sourceType, sourceAdapter))} else {parts = append(parts, fmt.Sprintf("source: %s", sourceType))}- } else if sourceAdapter := strings.TrimSpace(string(change.SourceAdapter)); sourceAdapter != "" {+ } else if sourceAdapter := strings.TrimSpace(presentation.SourceAdapter); sourceAdapter != "" {parts = append(parts, fmt.Sprintf("source: %s", sourceAdapter))}- if actor := strings.TrimSpace(change.Actor); actor != "" {+ if actor := strings.TrimSpace(presentation.Actor); actor != "" {parts = append(parts, fmt.Sprintf("actor: %s", actor))}- if reason := strings.TrimSpace(change.Reason); reason != "" {+ if reason := strings.TrimSpace(presentation.Reason); reason != "" {parts = append(parts, reason)}- if len(change.RelatedResources) > 0 {- related := make([]string, 0, len(change.RelatedResources))- for _, resourceID := range change.RelatedResources {+ if len(presentation.RelatedResources) > 0 {+ related := make([]string, 0, len(presentation.RelatedResources))+ for _, resourceID := range presentation.RelatedResources {if trimmed := strings.TrimSpace(resourceID); trimmed != "" {related = append(related, trimmed)}diff --git a/internal/ai/patrol_ai_intelligence_test.go b/internal/ai/patrol_ai_intelligence_test.goindex 3e9182d1d4..a679e33557 100644--- a/internal/ai/patrol_ai_intelligence_test.go+++ b/internal/ai/patrol_ai_intelligence_test.go@@ -438,6 +438,36 @@ func TestSeedPrecomputeIntelligenceState_UsesCanonicalResourceTimeline(t *testin}}+func TestPatrolRecentChangeFromUnified_UsesCanonicalChangePresentation(t *testing.T) {+ change := ur.ResourceChange{+ Kind: ur.ChangeAnomaly,+ From: " old-state ",+ To: " new-state ",+ SourceType: ur.SourcePulseDiff,+ SourceAdapter: ur.AdapterOpsAgent,+ Actor: " agent:ops-helper ",+ Reason: " incident changed ",+ RelatedResources: []string{"", " related-1 "},+ }++ memoryChange := patrolRecentChangeFromUnified(change)+ if memoryChange.ChangeType != "Metric anomaly" {+ t.Fatalf("unexpected change type: %q", memoryChange.ChangeType)+ }+ if !strings.Contains(memoryChange.Description, "Metric anomaly") {+ t.Fatalf("expected canonical description to contain label, got %q", memoryChange.Description)+ }+ if !strings.Contains(memoryChange.Description, "source: pulse_diff via agent:ops-helper") {+ t.Fatalf("expected canonical description to contain provenance, got %q", memoryChange.Description)+ }+ if !strings.Contains(memoryChange.Description, "actor: agent:ops-helper") {+ t.Fatalf("expected canonical description to contain actor, got %q", memoryChange.Description)+ }+ if !strings.Contains(memoryChange.Description, "related: related-1") {+ t.Fatalf("expected canonical description to contain related resource, got %q", memoryChange.Description)+ }+}+func TestSeedFindingsAndContext_ResolvesMissingAndAddsNotes(t *testing.T) {now := time.Now()ps := NewPatrolService(nil, nil)diff --git a/internal/ai/service.go b/internal/ai/service.goindex 4b0cb8d7c4..2d95a004df 100644--- a/internal/ai/service.go+++ b/internal/ai/service.go@@ -4629,11 +4629,10 @@ func truncateString(s string, maxLen int) string {}func formatResourceChangeContext(change unifiedresources.ResourceChange) string {- label := formatResourceChangeKindLabel(change.Kind)- summary := fmt.Sprintf("**%s**", label)+ presentation := unifiedresources.DescribeChange(change)+ summary := fmt.Sprintf("**%s**", presentation.KindLabel)- if from := strings.TrimSpace(change.From); from != "" || strings.TrimSpace(change.To) != "" {- to := strings.TrimSpace(change.To)+ if from, to := strings.TrimSpace(presentation.From), strings.TrimSpace(presentation.To); from != "" || to != "" {if from == "" {summary += fmt.Sprintf(" → %s", to)} else if to == "" {@@ -4644,24 +4643,24 @@ func formatResourceChangeContext(change unifiedresources.ResourceChange) string}provenance := make([]string, 0, 2)- if sourceType := strings.TrimSpace(string(change.SourceType)); sourceType != "" {+ if sourceType := strings.TrimSpace(presentation.SourceType); sourceType != "" {provenance = append(provenance, sourceType)}- if sourceAdapter := strings.TrimSpace(string(change.SourceAdapter)); sourceAdapter != "" {+ if sourceAdapter := strings.TrimSpace(presentation.SourceAdapter); sourceAdapter != "" {provenance = append(provenance, sourceAdapter)}if len(provenance) > 0 {summary += fmt.Sprintf(" [%s]", strings.Join(provenance, "/"))}- if actor := strings.TrimSpace(change.Actor); actor != "" {+ if actor := strings.TrimSpace(presentation.Actor); actor != "" {summary += fmt.Sprintf("; actor %s", actor)}- if reason := strings.TrimSpace(change.Reason); reason != "" {+ if reason := strings.TrimSpace(presentation.Reason); reason != "" {summary += fmt.Sprintf("; %s", reason)}- if len(change.RelatedResources) > 0 {- summary += fmt.Sprintf("; related: %s", strings.Join(change.RelatedResources, ", "))+ if len(presentation.RelatedResources) > 0 {+ summary += fmt.Sprintf("; related: %s", strings.Join(presentation.RelatedResources, ", "))}ago := "recently"@@ -4672,29 +4671,6 @@ func formatResourceChangeContext(change unifiedresources.ResourceChange) stringreturn summary}-func formatResourceChangeKindLabel(kind unifiedresources.ChangeKind) string {- switch kind {- case unifiedresources.ChangeStateTransition:- return "State transition"- case unifiedresources.ChangeRestart:- return "Restart"- case unifiedresources.ChangeConfigUpdate:- return "Config update"- case unifiedresources.ChangeAnomaly:- return "Metric anomaly"- case unifiedresources.ChangeRelationship:- return "Relationship change"- case unifiedresources.ChangeCapability:- return "Capability change"- default:- raw := strings.TrimSpace(strings.ReplaceAll(string(kind), "_", " "))- if raw == "" {- return "Change"- }- return strings.ToUpper(raw[:1]) + raw[1:]- }-}-// buildEnrichedResourceContext adds historical intelligence to regular AI chat// This is what makes Pulse Pro valuable - context that Claude Code can't have:// - Baseline comparisons ("this is 2x normal")diff --git a/internal/unifiedresources/change_presentation.go b/internal/unifiedresources/change_presentation.gonew file mode 100644index 0000000000..8dea6f8e63--- /dev/null+++ b/internal/unifiedresources/change_presentation.go@@ -0,0 +1,68 @@+package unifiedresources++import "strings"++// ChangePresentation captures the canonical human-readable components for a+// resource change. Backend AI surfaces can render these fragments in different+// styles without duplicating the semantic mapping.+type ChangePresentation struct {+ KindLabel string+ From string+ To string+ SourceType string+ SourceAdapter string+ Actor string+ Reason string+ RelatedResources []string+}++// ChangeKindLabel returns the canonical human-readable label for a change kind.+func ChangeKindLabel(kind ChangeKind) string {+ switch kind {+ case ChangeStateTransition:+ return "State transition"+ case ChangeRestart:+ return "Restart"+ case ChangeConfigUpdate:+ return "Config update"+ case ChangeAnomaly:+ return "Metric anomaly"+ case ChangeRelationship:+ return "Relationship change"+ case ChangeCapability:+ return "Capability change"+ default:+ raw := strings.TrimSpace(strings.ReplaceAll(string(kind), "_", " "))+ if raw == "" {+ return "Change"+ }+ return strings.ToUpper(raw[:1]) + raw[1:]+ }+}++// DescribeChange returns the canonical presentation fragments for a change.+func DescribeChange(change ResourceChange) ChangePresentation {+ presentation := ChangePresentation{+ KindLabel: ChangeKindLabel(change.Kind),+ }++ presentation.From = strings.TrimSpace(change.From)+ presentation.To = strings.TrimSpace(change.To)++ presentation.SourceType = strings.TrimSpace(string(change.SourceType))+ presentation.SourceAdapter = strings.TrimSpace(string(change.SourceAdapter))++ presentation.Actor = strings.TrimSpace(change.Actor)+ presentation.Reason = strings.TrimSpace(change.Reason)++ if len(change.RelatedResources) > 0 {+ presentation.RelatedResources = make([]string, 0, len(change.RelatedResources))+ for _, resourceID := range change.RelatedResources {+ if trimmed := strings.TrimSpace(resourceID); trimmed != "" {+ presentation.RelatedResources = append(presentation.RelatedResources, trimmed)+ }+ }+ }++ return presentation+}diff --git a/internal/unifiedresources/change_presentation_test.go b/internal/unifiedresources/change_presentation_test.gonew file mode 100644index 0000000000..2b9f7b0328--- /dev/null+++ b/internal/unifiedresources/change_presentation_test.go@@ -0,0 +1,61 @@+package unifiedresources++import "testing"++func TestChangeKindLabel(t *testing.T) {+ cases := map[ChangeKind]string{+ ChangeStateTransition: "State transition",+ ChangeRestart: "Restart",+ ChangeConfigUpdate: "Config update",+ ChangeAnomaly: "Metric anomaly",+ ChangeRelationship: "Relationship change",+ ChangeCapability: "Capability change",+ ChangeKind("custom_kind"): "Custom kind",+ ChangeKind(""): "Change",+ }++ for kind, want := range cases {+ if got := ChangeKindLabel(kind); got != want {+ t.Fatalf("ChangeKindLabel(%q) = %q, want %q", kind, got, want)+ }+ }+}++func TestDescribeChange(t *testing.T) {+ change := ResourceChange{+ Kind: ChangeRelationship,+ From: " node-a ",+ To: "node-b",+ SourceType: SourcePulseDiff,+ SourceAdapter: AdapterOpsAgent,+ Actor: " agent:ops-helper ",+ Reason: " config refresh ",+ RelatedResources: []string{"", " related-1 ", "related-2"},+ }++ presentation := DescribeChange(change)+ if presentation.KindLabel != "Relationship change" {+ t.Fatalf("unexpected kind label: %q", presentation.KindLabel)+ }+ if presentation.From != "node-a" {+ t.Fatalf("unexpected from value: %q", presentation.From)+ }+ if presentation.To != "node-b" {+ t.Fatalf("unexpected to value: %q", presentation.To)+ }+ if presentation.SourceType != "pulse_diff" {+ t.Fatalf("unexpected source type value: %q", presentation.SourceType)+ }+ if presentation.SourceAdapter != "agent:ops-helper" {+ t.Fatalf("unexpected source adapter value: %q", presentation.SourceAdapter)+ }+ if presentation.Actor != "agent:ops-helper" {+ t.Fatalf("unexpected actor value: %q", presentation.Actor)+ }+ if presentation.Reason != "config refresh" {+ t.Fatalf("unexpected reason value: %q", presentation.Reason)+ }+ if len(presentation.RelatedResources) != 2 || presentation.RelatedResources[0] != "related-1" || presentation.RelatedResources[1] != "related-2" {+ t.Fatalf("unexpected related resources: %#v", presentation.RelatedResources)+ }+}diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.goindex 698d4bd3b1..962e7109c7 100644--- a/internal/unifiedresources/code_standards_test.go+++ b/internal/unifiedresources/code_standards_test.go@@ -314,6 +314,26 @@ func TestResourceChangeEmissionCoversRelationshipAndCapabilityChanges(t *testing}}+func TestResourceChangePresentationUsesCanonicalLabels(t *testing.T) {+ data, err := os.ReadFile(filepath.Join("change_presentation.go"))+ if err != nil {+ t.Fatalf("failed to read change_presentation.go: %v", err)+ }+ source := string(data)+ requiredSnippets := []string{+ "func ChangeKindLabel(kind ChangeKind) string",+ "func DescribeChange(change ResourceChange) ChangePresentation",+ "KindLabel: ChangeKindLabel(change.Kind)",+ "presentation.SourceType = strings.TrimSpace(string(change.SourceType))",+ "presentation.SourceAdapter = strings.TrimSpace(string(change.SourceAdapter))",+ }+ for _, snippet := range requiredSnippets {+ if !strings.Contains(source, snippet) {+ t.Fatalf("internal/unifiedresources/change_presentation.go must pin canonical change presentation snippet %q", snippet)+ }+ }+}+func TestResourceFacetCountsAreCanonicalResourceFields(t *testing.T) {typesData, err := os.ReadFile(filepath.Join("types.go"))if err != nil {