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 aiSafeSummary policy decisions

rcourtman1d1c7bf6363e
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index d20b4a132e..2559aea42a 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -199,6 +199,10 @@ The unified AI resource data-governance block must also use the shared
unified-resource redaction-label helper directly, so the same canonical
policy labels back both the posture summary and the governed prompt context
without an AI-local wrapper.
+The governed query-fact and resource-context paths must also use the shared
+unified-resource policy helpers for the `aiSafeSummary` decision and
+redaction predicates, so the same local-only and redaction rules are applied
+consistently instead of being reimplemented in chat-local helpers.
The resource-intelligence payload used by the resource drawer also carries
the same canonical policy posture snapshot, so the detail surface can show
governed posture context without inventing a second posture contract.
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index d4beb14e1d..55cfeb83aa 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -165,6 +165,11 @@ The same shared policy presentation helper now also formats governed mention
policy lines and redaction lists for AI chat prefetch, so prompt context
stays aligned with the canonical sensitivity, routing, and redaction labels
instead of rebuilding them in lane-local helpers.
+The same shared policy helper also owns the `aiSafeSummary` decision and
+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.
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 2610875ba4..986b68a222 100644
--- a/internal/ai/chat/knowledge_extractor.go
+++ b/internal/ai/chat/knowledge_extractor.go
@@ -80,36 +80,8 @@ func extractQueryFacts(input map[string]interface{}, resultText string) []FactEn
}
}
-func queryFactUsesAISafeSummary(summary string, policy *unifiedresources.ResourcePolicy) bool {
- if strings.TrimSpace(summary) == "" || policy == nil {
- return false
- }
- if policy.Routing.Scope == unifiedresources.ResourceRoutingScopeLocalOnly {
- return true
- }
- return queryFactRedacts(policy,
- unifiedresources.ResourceRedactionAlias,
- unifiedresources.ResourceRedactionHostname,
- unifiedresources.ResourceRedactionPlatformID,
- )
-}
-
-func queryFactRedacts(policy *unifiedresources.ResourcePolicy, hints ...unifiedresources.ResourceRedactionHint) bool {
- if policy == nil {
- return false
- }
- for _, candidate := range policy.Routing.Redact {
- for _, hint := range hints {
- if candidate == hint {
- return true
- }
- }
- }
- return false
-}
-
func governedQueryFactLabel(name, aiSafeSummary string, policy *unifiedresources.ResourcePolicy) string {
- if queryFactUsesAISafeSummary(aiSafeSummary, policy) {
+ if unifiedresources.ResourcePolicyUsesAISafeSummary(aiSafeSummary, policy) {
return strings.TrimSpace(aiSafeSummary)
}
return strings.TrimSpace(name)
@@ -120,7 +92,7 @@ func governedQueryFactNodeLabel(name string, policy *unifiedresources.ResourcePo
if name == "" {
return ""
}
- if queryFactRedacts(policy,
+ if unifiedresources.ResourcePolicyRedacts(policy,
unifiedresources.ResourceRedactionAlias,
unifiedresources.ResourceRedactionHostname,
unifiedresources.ResourceRedactionPlatformID,
@@ -536,12 +508,12 @@ func extractQueryConfigFacts(input map[string]interface{}, resultText string) []
if resp.GuestType != "" {
parts = append(parts, resp.GuestType)
}
- if queryFactUsesAISafeSummary(resp.AISafeSummary, resp.Policy) {
+ if unifiedresources.ResourcePolicyUsesAISafeSummary(resp.AISafeSummary, resp.Policy) {
parts = append(parts, strings.TrimSpace(resp.AISafeSummary))
}
if resp.Hostname != "" {
hostname := resp.Hostname
- if queryFactRedacts(resp.Policy,
+ if unifiedresources.ResourcePolicyRedacts(resp.Policy,
unifiedresources.ResourceRedactionHostname,
unifiedresources.ResourceRedactionAlias,
unifiedresources.ResourceRedactionPlatformID,
diff --git a/internal/ai/resource_context.go b/internal/ai/resource_context.go
index dc584de2c9..c4d910969c 100644
--- a/internal/ai/resource_context.go
+++ b/internal/ai/resource_context.go
@@ -554,36 +554,12 @@ func unifiedResourceDisplayName(r unifiedresources.Resource) string {
}
func unifiedResourceContextLabel(r unifiedresources.Resource) string {
- if unifiedResourceContextUsesAISafeSummary(r) {
+ if unifiedresources.ResourcePolicyUsesAISafeSummary(r.AISafeSummary, r.Policy) {
return strings.TrimSpace(r.AISafeSummary)
}
return unifiedResourceDisplayName(r)
}
-func unifiedResourceContextUsesAISafeSummary(r unifiedresources.Resource) bool {
- if strings.TrimSpace(r.AISafeSummary) == "" || r.Policy == nil {
- return false
- }
- if r.Policy.Routing.Scope == unifiedresources.ResourceRoutingScopeLocalOnly {
- return true
- }
- return unifiedResourceContextRedacts(r, unifiedresources.ResourceRedactionAlias) ||
- unifiedResourceContextRedacts(r, unifiedresources.ResourceRedactionHostname) ||
- unifiedResourceContextRedacts(r, unifiedresources.ResourceRedactionPlatformID)
-}
-
-func unifiedResourceContextRedacts(r unifiedresources.Resource, hint unifiedresources.ResourceRedactionHint) bool {
- if r.Policy == nil {
- return false
- }
- for _, candidate := range r.Policy.Routing.Redact {
- if candidate == hint {
- return true
- }
- }
- return false
-}
-
func unifiedResourceContextClusterName(r unifiedresources.Resource) string {
name := ""
switch {
@@ -597,10 +573,7 @@ func unifiedResourceContextClusterName(r unifiedresources.Resource) string {
if name == "" {
return ""
}
- if unifiedResourceContextUsesAISafeSummary(r) ||
- unifiedResourceContextRedacts(r, unifiedresources.ResourceRedactionAlias) ||
- unifiedResourceContextRedacts(r, unifiedresources.ResourceRedactionHostname) ||
- unifiedResourceContextRedacts(r, unifiedresources.ResourceRedactionPlatformID) {
+ if unifiedresources.ResourcePolicyUsesAISafeSummary(r.AISafeSummary, r.Policy) {
return "redacted by policy"
}
return name
@@ -611,7 +584,7 @@ func unifiedResourceContextIPSummary(r unifiedresources.Resource, limit int) str
if len(ips) == 0 {
return ""
}
- if unifiedResourceContextRedacts(r, unifiedresources.ResourceRedactionIPAddress) {
+ if unifiedresources.ResourcePolicyRedacts(r.Policy, unifiedresources.ResourceRedactionIPAddress) {
return " - IPs redacted by policy"
}
if limit > 0 && len(ips) > limit {
diff --git a/internal/ai/resource_context_test.go b/internal/ai/resource_context_test.go
index 692887a184..0506fa1bab 100644
--- a/internal/ai/resource_context_test.go
+++ b/internal/ai/resource_context_test.go
@@ -375,6 +375,31 @@ func TestBuildUnifiedResourceContextUsesAISafeSummaryForSensitiveResources(t *te
}
}
+func TestResourcePolicyHelpersShareAISafeSummaryDecision(t *testing.T) {
+ policy := &unifiedresources.ResourcePolicy{
+ Sensitivity: unifiedresources.ResourceSensitivitySensitive,
+ Routing: unifiedresources.ResourceRoutingPolicy{
+ Scope: unifiedresources.ResourceRoutingScopeLocalFirst,
+ AllowCloudSummary: true,
+ AllowCloudRawSignals: false,
+ Redact: []unifiedresources.ResourceRedactionHint{
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionIPAddress,
+ },
+ },
+ }
+
+ if !unifiedresources.ResourcePolicyUsesAISafeSummary("virtual machine resource; status online; redacted for cloud summary", policy) {
+ t.Fatal("expected AI-safe summary helper to honor shared policy rules")
+ }
+ if !unifiedresources.ResourcePolicyRedacts(policy, unifiedresources.ResourceRedactionHostname) {
+ t.Fatal("expected hostname redaction helper to honor shared policy rules")
+ }
+ if unifiedresources.ResourcePolicyRedacts(policy, unifiedresources.ResourceRedactionAlias) {
+ t.Fatal("did not expect alias redaction helper to match")
+ }
+}
+
func TestBuildUnifiedResourceContext_UnifiedPath(t *testing.T) {
clusterID := "k8s-cluster-1"
k8sCluster := unifiedresources.Resource{
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index c524643359..5aa8356f11 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -283,6 +283,8 @@ func TestResourcePolicyPresentationUsesCanonicalLabels(t *testing.T) {
"ResourcePolicySensitivitySummaryFromCounts(",
"ResourcePolicyRoutingSummaryFromCounts(",
"ResourcePolicySummaryLines(",
+ "ResourcePolicyRedacts(",
+ "ResourcePolicyUsesAISafeSummary(",
}
for _, snippet := range requiredSnippets {
if !strings.Contains(source, snippet) {
diff --git a/internal/unifiedresources/policy_metadata_test.go b/internal/unifiedresources/policy_metadata_test.go
index 4ff600eedc..8623c07384 100644
--- a/internal/unifiedresources/policy_metadata_test.go
+++ b/internal/unifiedresources/policy_metadata_test.go
@@ -179,6 +179,37 @@ func TestResourcePolicySummaryLines(t *testing.T) {
}
}
+func TestResourcePolicyRedactsAndUsesAISafeSummary(t *testing.T) {
+ policy := &ResourcePolicy{
+ Sensitivity: ResourceSensitivitySensitive,
+ Routing: ResourceRoutingPolicy{
+ Scope: ResourceRoutingScopeLocalFirst,
+ AllowCloudSummary: true,
+ AllowCloudRawSignals: false,
+ Redact: []ResourceRedactionHint{
+ ResourceRedactionHostname,
+ ResourceRedactionIPAddress,
+ },
+ },
+ }
+
+ if !ResourcePolicyRedacts(policy, ResourceRedactionHostname) {
+ t.Fatal("expected hostname to be redacted")
+ }
+ if ResourcePolicyRedacts(policy, ResourceRedactionAlias) {
+ t.Fatal("did not expect alias to be redacted")
+ }
+ if !ResourcePolicyUsesAISafeSummary("resource summary safe for remote AI use", policy) {
+ t.Fatal("expected AI-safe summary to be used")
+ }
+ if ResourcePolicyUsesAISafeSummary("", policy) {
+ t.Fatal("did not expect empty summary to be used")
+ }
+ if ResourcePolicyUsesAISafeSummary("resource summary safe for remote AI use", nil) {
+ t.Fatal("did not expect nil policy to use AI-safe summary")
+ }
+}
+
func containsRedactionHint(hints []ResourceRedactionHint, want ResourceRedactionHint) bool {
for _, hint := range hints {
if hint == want {
diff --git a/internal/unifiedresources/policy_presentation.go b/internal/unifiedresources/policy_presentation.go
index 0c6698add9..c4be2dddf6 100644
--- a/internal/unifiedresources/policy_presentation.go
+++ b/internal/unifiedresources/policy_presentation.go
@@ -185,3 +185,34 @@ func ResourcePolicySummaryLines(policy *ResourcePolicy) []string {
return lines
}
+
+// ResourcePolicyRedacts reports whether the policy redacts any of the provided hints.
+func ResourcePolicyRedacts(policy *ResourcePolicy, hints ...ResourceRedactionHint) bool {
+ if policy == nil {
+ return false
+ }
+ for _, candidate := range policy.Routing.Redact {
+ for _, hint := range hints {
+ if candidate == hint {
+ return true
+ }
+ }
+ }
+ return false
+}
+
+// ResourcePolicyUsesAISafeSummary reports whether the canonical aiSafeSummary
+// should be used instead of raw resource labels for governed output.
+func ResourcePolicyUsesAISafeSummary(summary string, policy *ResourcePolicy) bool {
+ if strings.TrimSpace(summary) == "" || policy == nil {
+ return false
+ }
+ if policy.Routing.Scope == ResourceRoutingScopeLocalOnly {
+ return true
+ }
+ return ResourcePolicyRedacts(policy,
+ ResourceRedactionAlias,
+ ResourceRedactionHostname,
+ ResourceRedactionPlatformID,
+ )
+}