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.

Centralize governed label helpers

rcourtmanab44a5d09b3b
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index cdadbeb3b0..15698b54c7 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -153,6 +153,9 @@ AI-facing policy metadata must also be cloned through the shared unified-
resource policy helper so chat and tools consumers do not maintain their own
policy copy logic. Chat mention prefetch now calls that shared helper directly
at each resolved mention site rather than going through an AI-local wrapper.
+Chat knowledge extraction and resource-context rendering now also consume the
+shared unified-resource label helpers directly, so governed labels and
+redacted values stay consistent without AI-local presentation shims.
That shared presentation layer also owns the elapsed-time and "ago" wording
utilities, so the same "time ago" phrasing stays consistent across resource,
incident, and fallback memory summaries instead of being reformatted
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index c9ac552638..ed95ad9f0c 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -188,8 +188,10 @@ redaction predicates used by AI chat knowledge extraction and resource
context rendering, so governed labels and summary selection stay rooted in
the unified resource policy model instead of being duplicated in chat-local
helpers. Chat consumers now call `CloneResourcePolicy(...)` directly from the
-shared unified-resource contract, so policy copying stays centralized in the
-resource model rather than hidden behind an AI-local shim.
+shared unified-resource contract, and their governed labels now flow through
+shared `ResourcePolicyLabel(...)` and `ResourcePolicyRedactedValue(...)`
+helpers instead of through AI-local presentation shims, so policy copying and
+policy-bound labels both stay centralized in the resource model.
That same shared store now also persists append-only action lifecycle, action
audit, and export audit records, giving the control-plane verbs a durable home
diff --git a/internal/ai/chat/knowledge_extractor.go b/internal/ai/chat/knowledge_extractor.go
index 986b68a222..233316b941 100644
--- a/internal/ai/chat/knowledge_extractor.go
+++ b/internal/ai/chat/knowledge_extractor.go
@@ -80,28 +80,6 @@ func extractQueryFacts(input map[string]interface{}, resultText string) []FactEn
}
}
-func governedQueryFactLabel(name, aiSafeSummary string, policy *unifiedresources.ResourcePolicy) string {
- if unifiedresources.ResourcePolicyUsesAISafeSummary(aiSafeSummary, policy) {
- return strings.TrimSpace(aiSafeSummary)
- }
- return strings.TrimSpace(name)
-}
-
-func governedQueryFactNodeLabel(name string, policy *unifiedresources.ResourcePolicy) string {
- name = strings.TrimSpace(name)
- if name == "" {
- return ""
- }
- if unifiedresources.ResourcePolicyRedacts(policy,
- unifiedresources.ResourceRedactionAlias,
- unifiedresources.ResourceRedactionHostname,
- unifiedresources.ResourceRedactionPlatformID,
- ) {
- return "redacted by policy"
- }
- return name
-}
-
func extractQueryGetFacts(input map[string]interface{}, resultText string) []FactEntry {
// Tool results are direct JSON (NewJSONResult), no ToolResponse wrapper.
// ResourceResponse has nested CPU/Memory structs.
@@ -171,7 +149,7 @@ func extractQueryGetFacts(input map[string]interface{}, resultText string) []Fac
if resource.Status != "" {
parts = append(parts, resource.Status)
}
- if label := governedQueryFactLabel(resource.Name, resource.AISafeSummary, resource.Policy); label != "" {
+ if label := unifiedresources.ResourcePolicyLabel(resource.Name, resource.AISafeSummary, resource.Policy); label != "" {
parts = append(parts, label)
}
if resource.CPU.Percent > 0 {
@@ -239,7 +217,7 @@ func extractQuerySearchFacts(input map[string]interface{}, resultText string) []
limit = len(resp.Matches)
}
for _, m := range resp.Matches[:limit] {
- entry := governedQueryFactLabel(m.Name, m.AISafeSummary, m.Policy)
+ entry := unifiedresources.ResourcePolicyLabel(m.Name, m.AISafeSummary, m.Policy)
if entry == "" {
entry = m.Name
}
@@ -291,9 +269,13 @@ func extractQueryTopologyFacts(resultText string) []FactEntry {
if status == "" {
status = "unknown"
}
- label := governedQueryFactLabel(n.Name, n.AISafeSummary, n.Policy)
+ label := unifiedresources.ResourcePolicyLabel(n.Name, n.AISafeSummary, n.Policy)
if label == "" {
- label = governedQueryFactNodeLabel(n.Name, n.Policy)
+ label = unifiedresources.ResourcePolicyRedactedValue(n.Name, n.Policy,
+ unifiedresources.ResourceRedactionAlias,
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionPlatformID,
+ )
}
nodeDescs = append(nodeDescs, fmt.Sprintf("%s=%s", label, status))
}
@@ -512,14 +494,11 @@ func extractQueryConfigFacts(input map[string]interface{}, resultText string) []
parts = append(parts, strings.TrimSpace(resp.AISafeSummary))
}
if resp.Hostname != "" {
- hostname := resp.Hostname
- if unifiedresources.ResourcePolicyRedacts(resp.Policy,
+ hostname := unifiedresources.ResourcePolicyRedactedValue(resp.Hostname, resp.Policy,
unifiedresources.ResourceRedactionHostname,
unifiedresources.ResourceRedactionAlias,
unifiedresources.ResourceRedactionPlatformID,
- ) {
- hostname = "redacted by policy"
- }
+ )
parts = append(parts, "hostname="+hostname)
}
if resp.OSType != "" {
diff --git a/internal/ai/chat/knowledge_extractor_test.go b/internal/ai/chat/knowledge_extractor_test.go
index 6202317c8c..be64cbad9c 100644
--- a/internal/ai/chat/knowledge_extractor_test.go
+++ b/internal/ai/chat/knowledge_extractor_test.go
@@ -5,6 +5,7 @@ import (
"fmt"
"testing"
+ "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -971,7 +972,7 @@ func TestExtractFacts_QueryConfig_UsesGovernedSummary(t *testing.T) {
facts := ExtractFacts("pulse_query", input, result)
require.Len(t, facts, 2)
assert.Contains(t, facts[0].Value, "system container resource; status online; linked to parent resource; redacted for cloud summary")
- assert.Contains(t, facts[0].Value, "hostname=redacted by policy")
+ assert.Contains(t, facts[0].Value, "hostname="+unifiedresources.ResourcePolicyRedactedLabel)
assert.NotContains(t, facts[0].Value, "postfix.internal")
assert.NotContains(t, facts[0].Value, "postfix-server")
}
diff --git a/internal/ai/resource_context.go b/internal/ai/resource_context.go
index c4d910969c..baa60e6405 100644
--- a/internal/ai/resource_context.go
+++ b/internal/ai/resource_context.go
@@ -203,7 +203,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s** (%s)%s%s [%s]",
- unifiedResourceContextLabel(node), agentStatus, clusterInfo, metrics, node.Status))
+ unifiedresources.ResourcePolicyLabel(node.Name, node.AISafeSummary, node.Policy), agentStatus, clusterInfo, metrics, node.Status))
}
}
@@ -224,7 +224,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s**%s%s [%s]",
- unifiedResourceContextLabel(host), ips, metrics, host.Status))
+ unifiedresources.ResourcePolicyLabel(host.Name, host.AISafeSummary, host.Policy), ips, metrics, host.Status))
}
}
@@ -241,7 +241,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s**%s [%s]",
- unifiedResourceContextLabel(host), metrics, host.Status))
+ unifiedresources.ResourcePolicyLabel(host.Name, host.AISafeSummary, host.Policy), metrics, host.Status))
}
}
@@ -264,7 +264,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s** (%d/%d containers running) [%s]",
- unifiedResourceContextLabel(host), runningCount, containerCount, host.Status))
+ unifiedresources.ResourcePolicyLabel(host.Name, host.AISafeSummary, host.Policy), runningCount, containerCount, host.Status))
}
}
@@ -283,7 +283,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
clusterInfo = fmt.Sprintf(" [cluster: %s]", name)
}
sections = append(sections, fmt.Sprintf("- **%s** (Cluster%s, %d nodes) [%s]",
- unifiedResourceContextLabel(cluster), clusterInfo, nodeCount, cluster.Status))
+ unifiedresources.ResourcePolicyLabel(cluster.Name, cluster.AISafeSummary, cluster.Policy), clusterInfo, nodeCount, cluster.Status))
}
for _, node := range k8sNodes {
@@ -309,7 +309,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s** (Node, %s)%s%s [%s]",
- unifiedResourceContextLabel(node), agentStatus, clusterInfo, metrics, node.Status))
+ unifiedresources.ResourcePolicyLabel(node.Name, node.AISafeSummary, node.Policy), agentStatus, clusterInfo, metrics, node.Status))
}
}
}
@@ -341,7 +341,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
for _, parentID := range parentIDs {
parentName := "unresolved parent resource"
if parent, ok := infraMap[parentID]; ok {
- parentName = unifiedResourceContextLabel(parent)
+ parentName = unifiedresources.ResourcePolicyLabel(parent.Name, parent.AISafeSummary, parent.Policy)
}
sections = append(sections, fmt.Sprintf("\n**On %s:**", parentName))
@@ -369,7 +369,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
ips := unifiedResourceContextIPSummary(workload, 2)
sections = append(sections, fmt.Sprintf(" - **%s** (%s%s)%s [%s]",
- unifiedResourceContextLabel(workload), typeLabel, vmidInfo, ips, workload.Status))
+ unifiedresources.ResourcePolicyLabel(workload.Name, workload.AISafeSummary, workload.Policy), typeLabel, vmidInfo, ips, workload.Status))
}
}
@@ -381,7 +381,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
for _, workload := range noParent {
ips := unifiedResourceContextIPSummary(workload, 2)
sections = append(sections, fmt.Sprintf(" - **%s** (%s)%s [%s]",
- unifiedResourceContextLabel(workload), workload.Type, ips, workload.Status))
+ unifiedresources.ResourcePolicyLabel(workload.Name, workload.AISafeSummary, workload.Policy), workload.Type, ips, workload.Status))
}
}
}
@@ -397,7 +397,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
displayName := strings.TrimSpace(alert.ResourceName)
if resourceID := strings.TrimSpace(alert.ResourceID); resourceID != "" {
if resource, ok := byResourceID[resourceID]; ok {
- displayName = unifiedResourceContextLabel(resource)
+ displayName = unifiedresources.ResourcePolicyLabel(resource.Name, resource.AISafeSummary, resource.Policy)
} else if displayName == "" {
displayName = resourceID
}
@@ -481,7 +481,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
cpuPercent = unifiedMetricPercent(resource.Metrics.CPU)
}
sections = append(sections, fmt.Sprintf("%d. **%s** (%s): %.1f%%",
- i+1, unifiedResourceContextLabel(resource), resource.Type, cpuPercent))
+ i+1, unifiedresources.ResourcePolicyLabel(resource.Name, resource.AISafeSummary, resource.Policy), resource.Type, cpuPercent))
}
}
@@ -494,7 +494,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
memPercent = unifiedMetricPercent(resource.Metrics.Memory)
}
sections = append(sections, fmt.Sprintf("%d. **%s** (%s): %.1f%%",
- i+1, unifiedResourceContextLabel(resource), resource.Type, memPercent))
+ i+1, unifiedresources.ResourcePolicyLabel(resource.Name, resource.AISafeSummary, resource.Policy), resource.Type, memPercent))
}
}
@@ -507,7 +507,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
diskPercent = unifiedMetricPercent(resource.Metrics.Disk)
}
sections = append(sections, fmt.Sprintf("%d. **%s** (%s): %.1f%%",
- i+1, unifiedResourceContextLabel(resource), resource.Type, diskPercent))
+ i+1, unifiedresources.ResourcePolicyLabel(resource.Name, resource.AISafeSummary, resource.Policy), resource.Type, diskPercent))
}
}
@@ -553,13 +553,6 @@ func unifiedResourceDisplayName(r unifiedresources.Resource) string {
return strings.TrimSpace(r.ID)
}
-func unifiedResourceContextLabel(r unifiedresources.Resource) string {
- if unifiedresources.ResourcePolicyUsesAISafeSummary(r.AISafeSummary, r.Policy) {
- return strings.TrimSpace(r.AISafeSummary)
- }
- return unifiedResourceDisplayName(r)
-}
-
func unifiedResourceContextClusterName(r unifiedresources.Resource) string {
name := ""
switch {
@@ -573,10 +566,11 @@ func unifiedResourceContextClusterName(r unifiedresources.Resource) string {
if name == "" {
return ""
}
- if unifiedresources.ResourcePolicyUsesAISafeSummary(r.AISafeSummary, r.Policy) {
- return "redacted by policy"
- }
- return name
+ return unifiedresources.ResourcePolicyRedactedValue(name, r.Policy,
+ unifiedresources.ResourceRedactionAlias,
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionPlatformID,
+ )
}
func unifiedResourceContextIPSummary(r unifiedresources.Resource, limit int) string {
@@ -585,7 +579,7 @@ func unifiedResourceContextIPSummary(r unifiedresources.Resource, limit int) str
return ""
}
if unifiedresources.ResourcePolicyRedacts(r.Policy, unifiedresources.ResourceRedactionIPAddress) {
- return " - IPs redacted by policy"
+ return " - IPs " + unifiedresources.ResourcePolicyRedactedLabel
}
if limit > 0 && len(ips) > limit {
ips = ips[:limit]
diff --git a/internal/ai/resource_context_test.go b/internal/ai/resource_context_test.go
index 0506fa1bab..6bc3b4151c 100644
--- a/internal/ai/resource_context_test.go
+++ b/internal/ai/resource_context_test.go
@@ -250,7 +250,7 @@ func TestBuildUnifiedResourceContext_FullContext(t *testing.T) {
assertContains("On unresolved parent resource")
assertContains("Other workloads")
assertContains("virtual machine resource; status online; linked to parent resource; redacted for cloud summary")
- assertContains("IPs redacted by policy")
+ assertContains("IPs " + unifiedresources.ResourcePolicyRedactedLabel)
assertContains("Resources with Active Alerts")
assertContains("CPU high")
assertContains("Infrastructure Summary")
@@ -361,7 +361,7 @@ func TestBuildUnifiedResourceContextUsesAISafeSummaryForSensitiveResources(t *te
if !strings.Contains(got, "virtual machine resource; status online; redacted for cloud summary") {
t.Fatalf("expected AI-safe summary for sensitive resource, got %q", got)
}
- if !strings.Contains(got, "IPs redacted by policy") {
+ if !strings.Contains(got, "IPs "+unifiedresources.ResourcePolicyRedactedLabel) {
t.Fatalf("expected sensitive IP redaction marker, got %q", got)
}
if strings.Contains(got, "finance-db") {
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index c2da1c9f05..740891a538 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -316,6 +316,35 @@ func TestResourcePolicyCloneHelperUsedByAIConsumers(t *testing.T) {
}
}
+func TestResourcePolicyLabelHelpersUsedByAIConsumers(t *testing.T) {
+ requiredSnippets := map[string][]string{
+ filepath.Join("..", "ai", "chat", "knowledge_extractor.go"): {
+ "unifiedresources.ResourcePolicyLabel(",
+ "unifiedresources.ResourcePolicyRedactedValue(",
+ },
+ filepath.Join("..", "ai", "resource_context.go"): {
+ "unifiedresources.ResourcePolicyLabel(",
+ "unifiedresources.ResourcePolicyRedactedValue(",
+ },
+ filepath.Join(".", "policy_presentation.go"): {
+ "func ResourcePolicyLabel(name, aiSafeSummary string, policy *ResourcePolicy) string",
+ "func ResourcePolicyRedactedValue(value string, policy *ResourcePolicy, hints ...ResourceRedactionHint) string",
+ "const ResourcePolicyRedactedLabel = \"redacted by policy\"",
+ },
+ }
+ for name, snippets := range requiredSnippets {
+ data, err := os.ReadFile(name)
+ if err != nil {
+ t.Fatalf("failed to read %s: %v", name, err)
+ }
+ for _, snippet := range snippets {
+ if !strings.Contains(string(data), snippet) {
+ t.Fatalf("%s must contain %q", name, snippet)
+ }
+ }
+ }
+}
+
func TestResourceTimelineStoreIndexesSupportFilteredReads(t *testing.T) {
data, err := os.ReadFile(filepath.Join("store.go"))
if err != nil {
diff --git a/internal/unifiedresources/policy_metadata_test.go b/internal/unifiedresources/policy_metadata_test.go
index fad3788c28..915bc7838c 100644
--- a/internal/unifiedresources/policy_metadata_test.go
+++ b/internal/unifiedresources/policy_metadata_test.go
@@ -210,6 +210,32 @@ func TestResourcePolicyRedactsAndUsesAISafeSummary(t *testing.T) {
}
}
+func TestResourcePolicyLabelHelpers(t *testing.T) {
+ policy := &ResourcePolicy{
+ Sensitivity: ResourceSensitivityRestricted,
+ Routing: ResourceRoutingPolicy{
+ Scope: ResourceRoutingScopeLocalOnly,
+ Redact: []ResourceRedactionHint{
+ ResourceRedactionHostname,
+ ResourceRedactionAlias,
+ },
+ },
+ }
+
+ if got := ResourcePolicyLabel(" fallback-name ", " governed summary ", policy); got != "governed summary" {
+ t.Fatalf("ResourcePolicyLabel() = %q, want governed summary", got)
+ }
+ if got := ResourcePolicyLabel(" fallback-name ", " governed summary ", nil); got != "fallback-name" {
+ t.Fatalf("ResourcePolicyLabel() with nil policy = %q, want fallback-name", got)
+ }
+ if got := ResourcePolicyRedactedValue(" host-01 ", policy, ResourceRedactionHostname, ResourceRedactionAlias); got != ResourcePolicyRedactedLabel {
+ t.Fatalf("ResourcePolicyRedactedValue() = %q, want %q", got, ResourcePolicyRedactedLabel)
+ }
+ if got := ResourcePolicyRedactedValue(" host-01 ", nil, ResourceRedactionHostname); got != "host-01" {
+ t.Fatalf("ResourcePolicyRedactedValue() with nil policy = %q, want host-01", got)
+ }
+}
+
func TestCloneResourcePolicy(t *testing.T) {
t.Parallel()
diff --git a/internal/unifiedresources/policy_presentation.go b/internal/unifiedresources/policy_presentation.go
index c4be2dddf6..d00d038737 100644
--- a/internal/unifiedresources/policy_presentation.go
+++ b/internal/unifiedresources/policy_presentation.go
@@ -6,6 +6,10 @@ import (
"strings"
)
+// ResourcePolicyRedactedLabel is the canonical human-readable label used when
+// governed policy hides a value.
+const ResourcePolicyRedactedLabel = "redacted by policy"
+
// ResourceSensitivityOrder captures the canonical presentation order for
// sensitivity counts across policy surfaces.
var ResourceSensitivityOrder = []ResourceSensitivity{
@@ -201,6 +205,27 @@ func ResourcePolicyRedacts(policy *ResourcePolicy, hints ...ResourceRedactionHin
return false
}
+// ResourcePolicyLabel returns the governed display label for a resource.
+func ResourcePolicyLabel(name, aiSafeSummary string, policy *ResourcePolicy) string {
+ if ResourcePolicyUsesAISafeSummary(aiSafeSummary, policy) {
+ return strings.TrimSpace(aiSafeSummary)
+ }
+ return strings.TrimSpace(name)
+}
+
+// ResourcePolicyRedactedValue returns the canonical redacted label when the
+// provided policy hides the supplied value.
+func ResourcePolicyRedactedValue(value string, policy *ResourcePolicy, hints ...ResourceRedactionHint) string {
+ value = strings.TrimSpace(value)
+ if value == "" {
+ return ""
+ }
+ if ResourcePolicyRedacts(policy, hints...) {
+ return ResourcePolicyRedactedLabel
+ }
+ return value
+}
+
// ResourcePolicyUsesAISafeSummary reports whether the canonical aiSafeSummary
// should be used instead of raw resource labels for governed output.
func ResourcePolicyUsesAISafeSummary(summary string, policy *ResourcePolicy) bool {