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 change presenter summaries

rcourtmanaf804dc8f238
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 0d113f4680..79b8b1d9c9 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -165,6 +165,10 @@ The canonical relationship-summary helper also feeds resource change records,
so AI timeline prompts read the same relationship wording and edge labels that
the unified-resource contract emits instead of building another summary shape
in AI-local code.
+The same shared change presenter also owns the resource state, restart,
+incident, and config summary fragments used by change emission, so the AI
+timeline prompt can reuse the canonical from/to wording before it formats the
+markdown section itself.
The Patrol-backed correlation endpoint, resource-intelligence payload, and
seed prompt correlations now flow through the shared AI intelligence facade
first, so the detector remains an implementation detail behind one canonical
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index aac2e49999..3d798a490c 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -169,6 +169,9 @@ For relationship changes, the `from` and `to` fields now summarize the actual
edge(s) rather than only the parent pointer, so the API contract keeps the
graph transition legible even before the frontend expands the related-resource
chips.
+The same relationship and change presenters now also own the state, restart,
+incident, and config summary fragments that feed those timeline values, so the
+API surface preserves the canonical wording before the frontend renders it.
Invalid `sourceAdapter` values are rejected at the API boundary, so the filter
contract stays aligned with the canonical adapter set rather than silently
falling back to an empty slice.
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index b9c3ba6ebf..889bcbe49e 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-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.
+That same presenter now also owns the resource state, restart, incident, and
+config summary fragments used by change emission, so the human-readable
+timeline values stay canonical even before they are wrapped into a full change
+summary.
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
diff --git a/internal/unifiedresources/change_emission.go b/internal/unifiedresources/change_emission.go
index 08f4371e76..2d7ffca116 100644
--- a/internal/unifiedresources/change_emission.go
+++ b/internal/unifiedresources/change_emission.go
@@ -287,59 +287,10 @@ func proxmoxLifecycleChanged(before, after Resource) bool {
return !reflect.DeepEqual(beforeProxmox, afterProxmox)
}
-func resourceStateSummary(resource Resource) string {
- status := resourceStatusString(resource.Status)
- if status == "" {
- status = "unknown"
- }
- return status
-}
-
-func resourceRestartSummary(resource Resource) string {
- parts := []string{resourceStateSummary(resource)}
- if resource.Docker != nil {
- parts = append(parts, fmt.Sprintf("docker.restartCount=%d", resource.Docker.RestartCount))
- if resource.Docker.UptimeSeconds > 0 {
- parts = append(parts, fmt.Sprintf("docker.uptimeSeconds=%d", resource.Docker.UptimeSeconds))
- }
- }
- if resource.Kubernetes != nil {
- parts = append(parts, fmt.Sprintf("kubernetes.restarts=%d", resource.Kubernetes.Restarts))
- if resource.Kubernetes.UptimeSeconds > 0 {
- parts = append(parts, fmt.Sprintf("kubernetes.uptimeSeconds=%d", resource.Kubernetes.UptimeSeconds))
- }
- }
- return strings.Join(parts, "|")
-}
-
func resourceIncidentChanged(before, after Resource) bool {
return resourceIncidentFingerprint(before.Incidents) != resourceIncidentFingerprint(after.Incidents)
}
-func resourceIncidentSummary(resource Resource) string {
- return resourceIncidentSummaryFromSlice(resource.Incidents)
-}
-
-func resourceIncidentSummaryFromSlice(incidents []ResourceIncident) string {
- if len(incidents) == 0 {
- return "none"
- }
-
- labels := make([]string, 0, len(incidents))
- for _, incident := range incidents {
- labels = append(labels, resourceIncidentLabel(incident))
- }
-
- sort.Strings(labels)
- if len(labels) == 1 {
- return labels[0]
- }
- if len(labels) <= 3 {
- return strings.Join(labels, ", ")
- }
- return fmt.Sprintf("%d incidents", len(labels))
-}
-
func resourceIncidentFingerprint(incidents []ResourceIncident) string {
if len(incidents) == 0 {
return "none"
@@ -360,20 +311,6 @@ func resourceIncidentFingerprint(incidents []ResourceIncident) string {
return strings.Join(labels, "||")
}
-func resourceIncidentLabel(incident ResourceIncident) string {
- code := strings.TrimSpace(incident.Code)
- if code == "" {
- code = "incident"
- }
- if severity := strings.TrimSpace(string(incident.Severity)); severity != "" {
- code += fmt.Sprintf("[%s]", severity)
- }
- if summary := strings.TrimSpace(incident.Summary); summary != "" {
- code += fmt.Sprintf(":%s", summary)
- }
- return code
-}
-
func resourceRelationSummary(resource Resource) string {
if summary := resourceRelationshipSummary(resource.Relationships); summary != "" {
return summary
@@ -388,10 +325,6 @@ func resourceRelationSummary(resource Resource) string {
return parentID
}
-func resourceConfigSummary(resource Resource) string {
- return fmt.Sprintf("%s|%s|%s|%s", resource.Type, resource.Technology, resource.Name, resource.CustomURL)
-}
-
func resourceStatusString(status ResourceStatus) string {
return strings.TrimSpace(string(status))
}
diff --git a/internal/unifiedresources/change_presentation.go b/internal/unifiedresources/change_presentation.go
index 7ab4155fe8..90d2b8323f 100644
--- a/internal/unifiedresources/change_presentation.go
+++ b/internal/unifiedresources/change_presentation.go
@@ -2,6 +2,7 @@ package unifiedresources
import (
"fmt"
+ "sort"
"strings"
"time"
@@ -73,6 +74,73 @@ func DescribeChange(change ResourceChange) ChangePresentation {
return presentation
}
+func resourceStateSummary(resource Resource) string {
+ status := resourceStatusString(resource.Status)
+ if status == "" {
+ status = "unknown"
+ }
+ return status
+}
+
+func resourceRestartSummary(resource Resource) string {
+ parts := []string{resourceStateSummary(resource)}
+ if resource.Docker != nil {
+ parts = append(parts, fmt.Sprintf("docker.restartCount=%d", resource.Docker.RestartCount))
+ if resource.Docker.UptimeSeconds > 0 {
+ parts = append(parts, fmt.Sprintf("docker.uptimeSeconds=%d", resource.Docker.UptimeSeconds))
+ }
+ }
+ if resource.Kubernetes != nil {
+ parts = append(parts, fmt.Sprintf("kubernetes.restarts=%d", resource.Kubernetes.Restarts))
+ if resource.Kubernetes.UptimeSeconds > 0 {
+ parts = append(parts, fmt.Sprintf("kubernetes.uptimeSeconds=%d", resource.Kubernetes.UptimeSeconds))
+ }
+ }
+ return strings.Join(parts, "|")
+}
+
+func resourceIncidentSummary(resource Resource) string {
+ return resourceIncidentSummaryFromSlice(resource.Incidents)
+}
+
+func resourceIncidentSummaryFromSlice(incidents []ResourceIncident) string {
+ if len(incidents) == 0 {
+ return "none"
+ }
+
+ labels := make([]string, 0, len(incidents))
+ for _, incident := range incidents {
+ labels = append(labels, resourceIncidentLabel(incident))
+ }
+
+ sort.Strings(labels)
+ if len(labels) == 1 {
+ return labels[0]
+ }
+ if len(labels) <= 3 {
+ return strings.Join(labels, ", ")
+ }
+ return fmt.Sprintf("%d incidents", len(labels))
+}
+
+func resourceIncidentLabel(incident ResourceIncident) string {
+ code := strings.TrimSpace(incident.Code)
+ if code == "" {
+ code = "incident"
+ }
+ if severity := strings.TrimSpace(string(incident.Severity)); severity != "" {
+ code += fmt.Sprintf("[%s]", severity)
+ }
+ if summary := strings.TrimSpace(incident.Summary); summary != "" {
+ code += fmt.Sprintf(":%s", summary)
+ }
+ return code
+}
+
+func resourceConfigSummary(resource Resource) string {
+ return fmt.Sprintf("%s|%s|%s|%s", resource.Type, resource.Technology, resource.Name, resource.CustomURL)
+}
+
// FormatResourceChangeSummary returns the canonical one-line human-readable
// summary used by AI prompt sections and recent-change feeds.
func FormatResourceChangeSummary(change ResourceChange) string {
@@ -117,6 +185,48 @@ func FormatResourceChangeSummary(change ResourceChange) string {
return summary + fmt.Sprintf(" (%s)", ago)
}
+func resourceRelationshipSummary(relationships []ResourceRelationship) string {
+ if len(relationships) == 0 {
+ return ""
+ }
+
+ summaries := make([]string, 0, len(relationships))
+ for _, relationship := range relationships {
+ sourceID := CanonicalResourceID(relationship.SourceID)
+ targetID := CanonicalResourceID(relationship.TargetID)
+ if sourceID == "" && targetID == "" {
+ continue
+ }
+
+ label := sourceID
+ if label == "" {
+ label = "?"
+ }
+ label += "->"
+ if targetID == "" {
+ label += "?"
+ } else {
+ label += targetID
+ }
+ if relationship.Type != "" {
+ label += fmt.Sprintf("[%s]", RelationshipTypeLabel(relationship.Type))
+ }
+ summaries = append(summaries, label)
+ }
+
+ if len(summaries) == 0 {
+ return ""
+ }
+ sort.Strings(summaries)
+ if len(summaries) == 1 {
+ return summaries[0]
+ }
+ if len(summaries) <= 3 {
+ return strings.Join(summaries, ", ")
+ }
+ return fmt.Sprintf("%d relationships", len(summaries))
+}
+
// FormatResourceRecentChangesContext returns the canonical markdown section
// used by AI prompt surfaces for recent unified-resource changes.
func FormatResourceRecentChangesContext(changes []ResourceChange, includeResourcePrefix bool, headingLevel string) string {
diff --git a/internal/unifiedresources/change_presentation_test.go b/internal/unifiedresources/change_presentation_test.go
index bf96ce1cd7..80d3e85f4c 100644
--- a/internal/unifiedresources/change_presentation_test.go
+++ b/internal/unifiedresources/change_presentation_test.go
@@ -4,6 +4,8 @@ import (
"strings"
"testing"
"time"
+
+ "github.com/rcourtman/pulse-go-rewrite/internal/storagehealth"
)
func TestChangeKindLabel(t *testing.T) {
@@ -64,6 +66,36 @@ func TestDescribeChange(t *testing.T) {
}
}
+func TestResourceChangeSummaries(t *testing.T) {
+ if got := resourceStateSummary(Resource{}); got != "unknown" {
+ t.Fatalf("resourceStateSummary(empty) = %q, want unknown", got)
+ }
+
+ if got := resourceRestartSummary(Resource{Status: StatusWarning}); got != "warning" {
+ t.Fatalf("resourceRestartSummary(status) = %q, want warning", got)
+ }
+
+ incidentSummary := resourceIncidentSummary(Resource{Incidents: []ResourceIncident{
+ {Code: "alpha", Severity: storagehealth.RiskCritical},
+ {Code: "beta", Summary: "needs attention"},
+ }})
+ if incidentSummary != "alpha[critical], beta:needs attention" {
+ t.Fatalf("resourceIncidentSummary() = %q, want canonical labels", incidentSummary)
+ }
+
+ if got := resourceIncidentSummaryFromSlice(nil); got != "none" {
+ t.Fatalf("resourceIncidentSummaryFromSlice(nil) = %q, want none", got)
+ }
+
+ if got := resourceIncidentLabel(ResourceIncident{}); got != "incident" {
+ t.Fatalf("resourceIncidentLabel(empty) = %q, want incident", got)
+ }
+
+ if got := resourceConfigSummary(Resource{Type: "vm", Technology: "proxmox", Name: "vm-1", CustomURL: "https://example"}); got != "vm|proxmox|vm-1|https://example" {
+ t.Fatalf("resourceConfigSummary() = %q, want canonical config summary", got)
+ }
+}
+
func TestFormatResourceChangeSummary(t *testing.T) {
cases := []struct {
name string
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index 7738b19f04..df62d94dc9 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -537,8 +537,6 @@ func TestResourceChangeEmissionCoversRelationshipAndCapabilityChanges(t *testing
"changed = append(changed, \"kubernetes.restarts\", \"kubernetes.uptimeSeconds\")",
"if !reflect.DeepEqual(before.Capabilities, after.Capabilities) {",
"changed = append(changed, \"capabilities\")",
- "resourceRestartSummary(resource Resource) string",
- "resourceIncidentSummary(resource Resource) string",
}
for _, snippet := range requiredSnippets {
if !strings.Contains(source, snippet) {
@@ -557,6 +555,13 @@ func TestResourceChangePresentationUsesCanonicalLabels(t *testing.T) {
"func ChangeKindLabel(kind ChangeKind) string",
"func DescribeChange(change ResourceChange) ChangePresentation",
"func FormatResourceChangeSummary(change ResourceChange) string",
+ "func resourceRelationshipSummary(relationships []ResourceRelationship) string",
+ "resourceStateSummary(resource Resource) string",
+ "resourceRestartSummary(resource Resource) string",
+ "resourceIncidentSummary(resource Resource) string",
+ "resourceIncidentSummaryFromSlice(incidents []ResourceIncident) string",
+ "resourceIncidentLabel(incident ResourceIncident) string",
+ "resourceConfigSummary(resource Resource) string",
"KindLabel: ChangeKindLabel(change.Kind)",
"presentation.SourceType = strings.TrimSpace(string(change.SourceType))",
"presentation.SourceAdapter = strings.TrimSpace(string(change.SourceAdapter))",
@@ -589,23 +594,6 @@ func TestResourceGraphContextUsesCanonicalRelationshipPresentation(t *testing.T)
}
}
-func TestResourceRelationshipSummaryUsesCanonicalRelationshipPresentation(t *testing.T) {
- data, err := os.ReadFile(filepath.Join("relationship_presentation.go"))
- if err != nil {
- t.Fatalf("failed to read relationship_presentation.go: %v", err)
- }
- source := string(data)
- requiredSnippets := []string{
- "func resourceRelationshipSummary(relationships []ResourceRelationship) string",
- "label += fmt.Sprintf(\"[%s]\", RelationshipTypeLabel(relationship.Type))",
- }
- for _, snippet := range requiredSnippets {
- if !strings.Contains(source, snippet) {
- t.Fatalf("internal/unifiedresources/relationship_presentation.go must pin canonical relationship summary snippet %q", snippet)
- }
- }
-}
-
func TestPatrolSeedCorrelationContextUsesCanonicalSummaryFormatter(t *testing.T) {
data, err := os.ReadFile(filepath.Join("..", "ai", "patrol_ai.go"))
if err != nil {
diff --git a/internal/unifiedresources/relationship_presentation.go b/internal/unifiedresources/relationship_presentation.go
index 9e6873d2ce..20e267330c 100644
--- a/internal/unifiedresources/relationship_presentation.go
+++ b/internal/unifiedresources/relationship_presentation.go
@@ -2,7 +2,6 @@ package unifiedresources
import (
"fmt"
- "sort"
"strings"
"time"
@@ -69,50 +68,6 @@ func DescribeRelationship(rel ResourceRelationship) RelationshipPresentation {
return presentation
}
-// resourceRelationshipSummary returns the canonical compact label for a set
-// of relationships used by resource change timelines and related context.
-func resourceRelationshipSummary(relationships []ResourceRelationship) string {
- if len(relationships) == 0 {
- return ""
- }
-
- summaries := make([]string, 0, len(relationships))
- for _, relationship := range relationships {
- sourceID := CanonicalResourceID(relationship.SourceID)
- targetID := CanonicalResourceID(relationship.TargetID)
- if sourceID == "" && targetID == "" {
- continue
- }
-
- label := sourceID
- if label == "" {
- label = "?"
- }
- label += "->"
- if targetID == "" {
- label += "?"
- } else {
- label += targetID
- }
- if relationship.Type != "" {
- label += fmt.Sprintf("[%s]", RelationshipTypeLabel(relationship.Type))
- }
- summaries = append(summaries, label)
- }
-
- if len(summaries) == 0 {
- return ""
- }
- sort.Strings(summaries)
- if len(summaries) == 1 {
- return summaries[0]
- }
- if len(summaries) <= 3 {
- return strings.Join(summaries, ", ")
- }
- return fmt.Sprintf("%d relationships", len(summaries))
-}
-
// FormatResourceGraphContext returns the canonical AI prompt section for a
// resource's learned relationships.
func FormatResourceGraphContext(resource *Resource, limit int) string {