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
Centralize resource change summary formatting
rcourtman85914c21b92d
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 5fb45e7062..7d84713eec 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -168,6 +168,10 @@ That graph section is now rendered by the shared`internal/unifiedresources.FormatResourceGraphContext` helper, so the servicelayer only resolves the canonical resource and does not rebuild the sectionformat locally.+The canonical recent-change sentence formatting also lives in+`internal/unifiedresources.FormatResourceChangeSummary`, so AI runtime prompt+sections and Patrol seed context reuse the same change wording instead of+keeping another lane-local formatter.The related-resource correlation section now also comes from the sharedcorrelation formatter in `internal/ai/correlation`, so resource chat andincident prompts reuse the same learned-edge wording instead of rebuilding adiff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.mdindex 3bc9ff88a3..5042eca957 100644--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md@@ -148,6 +148,10 @@ The backend Patrol and AI runtime summaries now also share`internal/unifiedresources/change_presentation.go` for the canonicalchange-kind and provenance mapping, so the same resource-model semanticsdrive both the backend summaries and the frontend presentation helpers.+That same helper now also owns the one-line recent-change summary text used+by the AI runtime prompt sections and Patrol seed context, so the change+wording itself stays canonical before the surrounding section headers are+applied.The canonical shared AI resource context now also surfaces policy routing andredaction hints from unified resources, so the Patrol page and resource drawersee the same governance posture that the runtime uses for export boundaries.diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex c7d33f505e..5fcf55d362 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -97,6 +97,10 @@ kind, source type, source adapter, actor, reason, and related-resourcefragments from `internal/unifiedresources/change_presentation.go`, so thesemantic mapping lives with the resource model instead of being duplicated inlane-local prompt helpers.+That same change-presentation helper now also owns the one-line+`FormatResourceChangeSummary` used by AI runtime recent-change sections and+Patrol seed context, so the change wording itself stays canonical before any+section-specific headings are applied.The backend AI and Patrol graph context renderers now derive their canonicalrelationship labels, direction, provenance, freshness, and metadata flagsfrom `internal/unifiedresources/relationship_presentation.go`, so the graphdiff --git a/internal/ai/coverage_increase_test.go b/internal/ai/coverage_increase_test.goindex dbf478eb87..5baa8915b0 100644--- a/internal/ai/coverage_increase_test.go+++ b/internal/ai/coverage_increase_test.go@@ -324,6 +324,17 @@ func TestService_BuildEnrichedResourceContext(t *testing.T) {s.resourceExportStoreOrgID = s.orgIDs.mu.Unlock()+ recentCtx := s.buildRecentResourceChangesContext("res1")+ if !strings.Contains(recentCtx, "Restart") {+ t.Fatalf("expected canonical recent change summary to include restart label, got %q", recentCtx)+ }+ if !strings.Contains(recentCtx, "platform_event/proxmox_adapter") {+ t.Fatalf("expected canonical recent change summary to include shared provenance, got %q", recentCtx)+ }+ if !strings.Contains(recentCtx, "Routine restart requested") {+ t.Fatalf("expected canonical recent change summary to include reason, got %q", recentCtx)+ }+ctx = s.buildEnrichedResourceContext("res1", "node", metrics)t.Logf("Enriched context (canonical changes): %s", ctx)diff --git a/internal/ai/intelligence.go b/internal/ai/intelligence.goindex 7c4db38d94..915270a6a9 100644--- a/internal/ai/intelligence.go+++ b/internal/ai/intelligence.go@@ -550,7 +550,7 @@ func formatCanonicalRecentChangesContext(changes []unifiedresources.ResourceChanlines := []string{heading, "What changed recently:"}for _, change := range changes {- entry := formatResourceChangeContext(change)+ entry := unifiedresources.FormatResourceChangeSummary(change)if includeResourcePrefix {if resourceID := strings.TrimSpace(change.ResourceID); resourceID != "" {entry = fmt.Sprintf("%s: %s", resourceID, entry)diff --git a/internal/ai/patrol_ai.go b/internal/ai/patrol_ai.goindex eba70311d2..8cf27f1788 100644--- a/internal/ai/patrol_ai.go+++ b/internal/ai/patrol_ai.go@@ -1692,13 +1692,12 @@ 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(presentation.KindLabel),+ ChangeType: memory.ChangeType(unifiedresources.ChangeKindLabel(change.Kind)),DetectedAt: patrolRecentChangeDetectedAt(change),- Description: patrolFormatCanonicalRecentChangeDescription(presentation),+ Description: unifiedresources.FormatResourceChangeSummary(change),}}@@ -1712,53 +1711,6 @@ func patrolRecentChangeDetectedAt(change unifiedresources.ResourceChange) time.Treturn time.Now()}-func patrolFormatCanonicalRecentChangeDescription(presentation unifiedresources.ChangePresentation) string {- parts := []string{presentation.KindLabel}-- if from, to := strings.TrimSpace(presentation.From), strings.TrimSpace(presentation.To); from != "" || to != "" {- switch {- 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", to))- }- }-- 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(presentation.SourceAdapter); sourceAdapter != "" {- parts = append(parts, fmt.Sprintf("source: %s", sourceAdapter))- }-- if actor := strings.TrimSpace(presentation.Actor); actor != "" {- parts = append(parts, fmt.Sprintf("actor: %s", actor))- }-- if reason := strings.TrimSpace(presentation.Reason); reason != "" {- parts = append(parts, reason)- }-- 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)- }- }- if len(related) > 0 {- parts = append(parts, fmt.Sprintf("related: %s", strings.Join(related, ", ")))- }- }-- return strings.Join(parts, "; ")-}-// seedResourceInventory builds the node, guest, docker, storage, ceph, and PBS sections.type patrolNodeInventoryRow struct {id, name, status stringdiff --git a/internal/ai/patrol_ai_intelligence_test.go b/internal/ai/patrol_ai_intelligence_test.goindex f39d757c29..5b39dca9ae 100644--- a/internal/ai/patrol_ai_intelligence_test.go+++ b/internal/ai/patrol_ai_intelligence_test.go@@ -439,9 +439,9 @@ func TestSeedPrecomputeIntelligenceState_UsesCanonicalResourceTimeline(t *testint.Fatalf("expected canonical resource ID res-1, got %q", change.ResourceID)}for _, part := range []string{- "Config update",- "source: pulse_diff via agent:ops-helper",- "actor: agent:ops-helper",+ "**Config update**",+ "[pulse_diff/agent:ops-helper]",+ "; actor agent:ops-helper","related: related-1",} {if !strings.Contains(change.Description, part) {@@ -469,10 +469,10 @@ func TestPatrolRecentChangeFromUnified_UsesCanonicalChangePresentation(t *testinif !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") {+ if !strings.Contains(memoryChange.Description, "[pulse_diff/agent:ops-helper]") {t.Fatalf("expected canonical description to contain provenance, got %q", memoryChange.Description)}- if !strings.Contains(memoryChange.Description, "actor: agent:ops-helper") {+ 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") {diff --git a/internal/ai/service.go b/internal/ai/service.goindex c98c4ba150..f09405961c 100644--- a/internal/ai/service.go+++ b/internal/ai/service.go@@ -4587,7 +4587,7 @@ func (s *Service) buildRecentResourceChangesContext(resourceID string) string {if len(changeInfo) >= 3 {break}- changeInfo = append(changeInfo, formatResourceChangeContext(change))+ changeInfo = append(changeInfo, unifiedresources.FormatResourceChangeSummary(change))}if len(changeInfo) > 0 {return "\n\n### Recent Changes\n" + strings.Join(changeInfo, "\n")@@ -4653,7 +4653,7 @@ func (s *Service) buildResourceGraphContext(resourceID string) string {return unifiedresources.FormatResourceGraphContext(resource, 3)}-// truncateString truncates a string to maxLen characters+// truncateString truncates a string to maxLen characters.func truncateString(s string, maxLen int) string {if len(s) <= maxLen {return s@@ -4661,49 +4661,6 @@ func truncateString(s string, maxLen int) string {return s[:maxLen-3] + "..."}-func formatResourceChangeContext(change unifiedresources.ResourceChange) string {- presentation := unifiedresources.DescribeChange(change)- summary := fmt.Sprintf("**%s**", presentation.KindLabel)-- if from, to := strings.TrimSpace(presentation.From), strings.TrimSpace(presentation.To); from != "" || to != "" {- if from == "" {- summary += fmt.Sprintf(" → %s", to)- } else if to == "" {- summary += fmt.Sprintf(" %s →", from)- } else {- summary += fmt.Sprintf(" %s → %s", from, to)- }- }-- provenance := make([]string, 0, 2)- if sourceType := strings.TrimSpace(presentation.SourceType); sourceType != "" {- provenance = append(provenance, sourceType)- }- 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(presentation.Actor); actor != "" {- summary += fmt.Sprintf("; actor %s", actor)- }- if reason := strings.TrimSpace(presentation.Reason); reason != "" {- summary += fmt.Sprintf("; %s", reason)- }- if len(presentation.RelatedResources) > 0 {- summary += fmt.Sprintf("; related: %s", strings.Join(presentation.RelatedResources, ", "))- }-- ago := "recently"- if !change.ObservedAt.IsZero() {- ago = formatDuration(time.Since(change.ObservedAt).Truncate(time.Minute))- }- summary += fmt.Sprintf(" (%s ago)", ago)- return summary-}-// 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.goindex 8dea6f8e63..859692e733 100644--- a/internal/unifiedresources/change_presentation.go+++ b/internal/unifiedresources/change_presentation.go@@ -1,6 +1,10 @@package unifiedresources-import "strings"+import (+ "fmt"+ "strings"+ "time"+)// ChangePresentation captures the canonical human-readable components for a// resource change. Backend AI surfaces can render these fragments in different@@ -66,3 +70,47 @@ func DescribeChange(change ResourceChange) ChangePresentation {return presentation}++// FormatResourceChangeSummary returns the canonical one-line human-readable+// summary used by AI prompt sections and recent-change feeds.+func FormatResourceChangeSummary(change ResourceChange) string {+ presentation := DescribeChange(change)+ summary := fmt.Sprintf("**%s**", presentation.KindLabel)++ if from, to := strings.TrimSpace(presentation.From), strings.TrimSpace(presentation.To); from != "" || to != "" {+ if from == "" {+ summary += fmt.Sprintf(" → %s", to)+ } else if to == "" {+ summary += fmt.Sprintf(" %s →", from)+ } else {+ summary += fmt.Sprintf(" %s → %s", from, to)+ }+ }++ provenance := make([]string, 0, 2)+ if sourceType := strings.TrimSpace(presentation.SourceType); sourceType != "" {+ provenance = append(provenance, sourceType)+ }+ 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(presentation.Actor); actor != "" {+ summary += fmt.Sprintf("; actor %s", actor)+ }+ if reason := strings.TrimSpace(presentation.Reason); reason != "" {+ summary += fmt.Sprintf("; %s", reason)+ }+ if len(presentation.RelatedResources) > 0 {+ summary += fmt.Sprintf("; related: %s", strings.Join(presentation.RelatedResources, ", "))+ }++ ago := "recently"+ if !change.ObservedAt.IsZero() {+ ago = formatDuration(time.Since(change.ObservedAt).Truncate(time.Minute))+ }+ return summary + fmt.Sprintf(" (%s ago)", ago)+}diff --git a/internal/unifiedresources/change_presentation_test.go b/internal/unifiedresources/change_presentation_test.goindex 2b9f7b0328..aa1c2cb70b 100644--- a/internal/unifiedresources/change_presentation_test.go+++ b/internal/unifiedresources/change_presentation_test.go@@ -1,6 +1,10 @@package unifiedresources-import "testing"+import (+ "strings"+ "testing"+ "time"+)func TestChangeKindLabel(t *testing.T) {cases := map[ChangeKind]string{@@ -59,3 +63,32 @@ func TestDescribeChange(t *testing.T) {t.Fatalf("unexpected related resources: %#v", presentation.RelatedResources)}}++func TestFormatResourceChangeSummary(t *testing.T) {+ change := ResourceChange{+ Kind: ChangeRestart,+ From: "running",+ To: "restarting",+ SourceType: SourcePlatformEvent,+ SourceAdapter: AdapterProxmox,+ Actor: "agent:oncall-helper",+ Reason: "Routine restart requested",+ RelatedResources: []string{"node-1"},+ ObservedAt: time.Now().Add(-2 * time.Hour),+ }++ summary := FormatResourceChangeSummary(change)+ for _, want := range []string{+ "**Restart**",+ "running → restarting",+ "platform_event/proxmox_adapter",+ "actor agent:oncall-helper",+ "Routine restart requested",+ "related: node-1",+ "2 hours ago",+ } {+ if !strings.Contains(summary, want) {+ t.Fatalf("expected summary %q to contain %q", summary, want)+ }+ }+}diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.goindex 804361ef60..e0dfa0afd1 100644--- a/internal/unifiedresources/code_standards_test.go+++ b/internal/unifiedresources/code_standards_test.go@@ -352,6 +352,7 @@ func TestResourceChangePresentationUsesCanonicalLabels(t *testing.T) {requiredSnippets := []string{"func ChangeKindLabel(kind ChangeKind) string","func DescribeChange(change ResourceChange) ChangePresentation",+ "func FormatResourceChangeSummary(change ResourceChange) string","KindLabel: ChangeKindLabel(change.Kind)","presentation.SourceType = strings.TrimSpace(string(change.SourceType))","presentation.SourceAdapter = strings.TrimSpace(string(change.SourceAdapter))",@@ -373,6 +374,7 @@ func TestResourceGraphContextUsesCanonicalRelationshipPresentation(t *testing.T)"func (s *Service) buildResourceGraphContext(resourceID string) string","if graphContext := s.buildResourceGraphContext(resourceID); graphContext != \"\" {","unifiedresources.FormatResourceGraphContext(resource, 3)",+ "unifiedresources.FormatResourceChangeSummary(change)","type canonicalResourceGetter interface {","correlationDetector.FormatForContext(resourceID)",}@@ -392,6 +394,7 @@ func TestPatrolSeedCorrelationContextUsesCanonicalSummaryFormatter(t *testing.T)requiredSnippets := []string{"# Known Resource Correlations","correlation.FormatCorrelationSummary(c)",+ "unifiedresources.FormatResourceChangeSummary(change)",}for _, snippet := range requiredSnippets {if !strings.Contains(source, snippet) {@@ -400,6 +403,23 @@ func TestPatrolSeedCorrelationContextUsesCanonicalSummaryFormatter(t *testing.T)}}+func TestIntelligenceRecentChangesUseCanonicalSummaryFormatter(t *testing.T) {+ data, err := os.ReadFile(filepath.Join("..", "ai", "intelligence.go"))+ if err != nil {+ t.Fatalf("failed to read intelligence.go: %v", err)+ }+ source := string(data)+ requiredSnippets := []string{+ "unifiedresources.FormatResourceChangeSummary(change)",+ "formatCanonicalRecentChangesContext(recent, includeResourcePrefix)",+ }+ for _, snippet := range requiredSnippets {+ if !strings.Contains(source, snippet) {+ t.Fatalf("internal/ai/intelligence.go must pin canonical recent-change snippet %q", snippet)+ }+ }+}+func TestResourceFacetCountsAreCanonicalResourceFields(t *testing.T) {typesData, err := os.ReadFile(filepath.Join("types.go"))if err != nil {