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.

Sanitize Assistant briefing handoffs

rcourtman39a5be31a0ca
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 2944fe6193..d77b44c525 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -202,6 +202,11 @@ runtime cost control, and shared AI transport surfaces.
unified-resource resolution and policy presentation helpers that govern
mention prefetch and provider-bound redaction; that context remains
model-only handling guidance, not saved user text or disclosure authority.
+ Before injecting any product-originated handoff context into the model
+ prompt, the runtime must also apply canonical resource-policy redaction to
+ the assembled handoff text itself, including operator briefings and
+ lower-level finding/action context, so local-model prompts and non-local
+ provider transport share the same governed identity boundary.
Assistant runtime may also hydrate current canonical resource-state context
for those handoff resources, including compact status, freshness,
source-health, metric, incident, and governed-capability summaries from the
@@ -947,7 +952,10 @@ finding, resource, priority, investigation confidence, recommended next step,
and governed action posture as operator guidance, while leaving current
resource-state, timeline, and action-audit hydration in the existing canonical
AI runtime handoff builders. It is explanation and review context only, not
-approval or execution authority.
+approval or execution authority. The assembled briefing is policy-sanitized by
+the chat handoff runtime before prompt injection, so governed resource names,
+IDs, aliases, nodes, paths, and addresses are redacted or represented through
+the canonical AI-safe summary instead of leaking through product prose.
The same page and drawer now also render their recent-change timeline through
the shared `frontend-modern/src/components/Infrastructure/ResourceChangeSummary.tsx`
card, so the canonical recent-change layout and relative-time wording stay
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 35b4b99d12..d7367b316b 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -314,7 +314,10 @@ the canonical monitored-system blocked payload.
keep `[Operator Briefing]`, `[Finding Context]`, structured handoff
resources, and structured handoff actions model-only, with the briefing
summarizing operator next steps and governed action posture without raw
- command text.
+ command text. Chat execution owns resource-policy sanitization of the
+ assembled model-only handoff before prompt injection, so API payload
+ builders may pass structured product context without turning raw resource
+ identity into user-authored text or disclosure authority.
4. Route unified resource sensitivity, routing, and `aiSafeSummary` payload changes through `internal/api/resources.go`, `internal/api/contract_test.go`, and the canonical frontend resource consumer proofs together; resource governance metadata must not ship as an API-only or frontend-only heuristic
That same resource payload contract owns `aggregations.policyPosture` on
`/api/resources` and `/api/resources/stats`. The aggregation must be derived
@@ -779,7 +782,12 @@ the canonical monitored-system blocked payload.
resource-policy context for those resources through unified-resource
resolution and shared policy presentation helpers, but the resulting handling
guidance is read-only, model-only context and must not become saved user text,
- disclosure authority, or action authority. Chat execution may also hydrate
+ disclosure authority, or action authority. Chat execution must apply that
+ same resource-policy boundary to the assembled product-originated handoff
+ text before model prompt injection, including operator briefings and
+ lower-level finding/action context, so governed resource identities are
+ redacted even when the selected model is local and no provider-bound
+ sanitizer will run. Chat execution may also hydrate
current canonical resource-state context for those resources, including
compact status, freshness, source-health, metric, incident, and
governed-capability summaries from the unified-resource model, but that
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 6cddca4645..03f968eca0 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -124,7 +124,11 @@ Patrol-specific presentation helpers.
briefing derived from the unified finding and structured investigation record
before the detailed finding context, so Assistant leads with the current risk,
conclusion, recommended next step, and governed approval/proposed-fix posture
- instead of behaving like a generic chat over a pasted incident dump.
+ instead of behaving like a generic chat over a pasted incident dump. The
+ assembled handoff must still pass through the Assistant runtime's
+ resource-policy sanitizer before prompt injection, so Patrol-owned prose
+ cannot leak governed resource names, IDs, aliases, nodes, paths, or
+ addresses outside the canonical policy boundary.
If the referenced finding is no longer current, Assistant must drop the
stored handoff instead of continuing from stale Patrol context. Assistant
handoff context must also carry the unified
diff --git a/docs/release-control/v6/internal/subsystems/security-privacy.md b/docs/release-control/v6/internal/subsystems/security-privacy.md
index b88b050956..15a0bd547e 100644
--- a/docs/release-control/v6/internal/subsystems/security-privacy.md
+++ b/docs/release-control/v6/internal/subsystems/security-privacy.md
@@ -153,7 +153,7 @@ controls as normal product settings.
behavior changes. Hosted commercial URL overrides must remain absolute
HTTP(S) URLs, with plain HTTP limited to loopback development origins.
8. Keep the Data Handling settings surface neutral and non-commercial: it may show resource policy posture, local-only counts, and redaction coverage, but it must not advertise trials, upgrades, paid plans, or monitoring limits.
-9. Keep operator-facing Data Handling posture aligned with runtime AI/context enforcement: `local-only` resource details must not be sent to external model prompts, and sensitive free-form alert, tool-result, investigation, handoff context, and any retained legacy managed-model compatibility text must use the shared resource-policy redaction helper before leaving the local trust boundary. Assistant handoffs may surface canonical policy handling guidance and current resource-state summaries for product-originated resources, but that guidance and state are model-only context and must not become disclosure authority. All provider-bound AI requests to non-local models must use the shared resource-policy sanitizer immediately before transport so later agentic turns cannot bypass the advertised handling posture.
+9. Keep operator-facing Data Handling posture aligned with runtime AI/context enforcement: `local-only` resource details must not be sent to external model prompts, and sensitive free-form alert, tool-result, investigation, handoff context, and any retained legacy managed-model compatibility text must use the shared resource-policy redaction helper before leaving the local trust boundary. Assistant handoffs may surface canonical policy handling guidance and current resource-state summaries for product-originated resources, but that guidance and state are model-only context and must not become disclosure authority. Product-originated Assistant handoff text must also be policy-cleaned before prompt injection, including operator briefings and finding/action context, so raw governed resource identity cannot leak through local-model briefing prose while non-local transport still receives the final provider-bound sanitizer. All provider-bound AI requests to non-local models must use the shared resource-policy sanitizer immediately before transport so later agentic turns cannot bypass the advertised handling posture.
10. Keep the canonical and frontend-served privacy disclosures aligned with
the actual AI transport boundary: self-managed installs must describe local
providers as staying on the operator network, non-local providers as direct
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index c96e86c67d..eb5078ac29 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -199,7 +199,10 @@ Canonical policy presentation and exact-value redaction helpers are owned in
`internal/unifiedresources/policy_presentation.go`. AI, Patrol, alert, export,
and prompt consumers must use those helpers for governed resource names,
hostnames, IP addresses, platform IDs, aliases, and paths instead of inventing
-consumer-local scrubbers.
+consumer-local scrubbers. When a consumer has product-originated resource
+references that are not guaranteed to be present on the canonical resource
+record, it must pass them through the shared redaction-reference helper rather
+than recomputing local policy checks.
Canonical policy posture aggregation is owned here as well. Resource API
payloads may expose a camelCase transport projection, but the counts must be
derived from `internal/unifiedresources/policy_posture.go` after canonical
diff --git a/internal/ai/chat/service.go b/internal/ai/chat/service.go
index 324072bfe7..eb2c3b5e7e 100644
--- a/internal/ai/chat/service.go
+++ b/internal/ai/chat/service.go
@@ -538,6 +538,7 @@ func (s *Service) ExecuteStream(ctx context.Context, req ExecuteRequest, callbac
handoffContext = mergeHandoffResourceRelationshipContext(handoffContext, handoffResources, handoffResourceProvider)
handoffContext = mergeHandoffResourceTimelineContext(handoffContext, handoffResources, handoffResourceProvider, s.actionAuditStore, time.Now())
handoffContext = mergeHandoffActionContext(handoffContext, handoffActions)
+ handoffContext = sanitizeHandoffContextForResourcePolicy(handoffContext, handoffResources, handoffResourceProvider)
injectHandoffContextIntoLatestUserMessage(messages, handoffContext)
// Determine which model/loop to use for this request.
@@ -853,6 +854,111 @@ func injectHandoffContextIntoLatestUserMessage(messages []Message, handoffContex
}
}
+func sanitizeHandoffContextForResourcePolicy(handoffContext string, handoffResources []HandoffResource, provider tools.UnifiedResourceProvider) string {
+ contextText := strings.TrimSpace(handoffContext)
+ resources := normalizeHandoffResources(handoffResources)
+ if contextText == "" || len(resources) == 0 || provider == nil {
+ return contextText
+ }
+
+ redacted := contextText
+ for _, handoffResource := range resources {
+ resource, ok := tools.CanonicalHandoffUnifiedResource(provider, handoffResource.ID, handoffResource.Name, handoffResource.Type, handoffResource.Node)
+ if !ok {
+ continue
+ }
+
+ policy, aiSafeSummary := unifiedresources.CanonicalGovernanceMetadata(&resource)
+ if policy == nil {
+ continue
+ }
+ resource.Policy = policy
+ resource.AISafeSummary = aiSafeSummary
+ redacted = unifiedresources.ResourcePolicyRedactedTextWithReferences(redacted, resource, handoffResourcePolicyReferences(handoffResource, resource)...)
+ }
+ return strings.TrimSpace(redacted)
+}
+
+func handoffResourcePolicyReferences(handoffResource HandoffResource, resource unifiedresources.Resource) []unifiedresources.ResourcePolicyRedactionReference {
+ references := make([]unifiedresources.ResourcePolicyRedactionReference, 0, 16)
+ add := func(value string, hints ...unifiedresources.ResourceRedactionHint) {
+ references = append(references, unifiedresources.ResourcePolicyReference(value, hints...))
+ }
+
+ add(resource.Name,
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ add(resource.ID,
+ unifiedresources.ResourceRedactionPlatformID,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ if resource.Canonical != nil {
+ add(resource.Canonical.DisplayName,
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ add(resource.Canonical.Hostname,
+ unifiedresources.ResourceRedactionHostname,
+ )
+ add(resource.Canonical.PlatformID,
+ unifiedresources.ResourceRedactionPlatformID,
+ )
+ add(resource.Canonical.PrimaryID,
+ unifiedresources.ResourceRedactionPlatformID,
+ )
+ for _, alias := range resource.Canonical.Aliases {
+ add(alias,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ }
+ }
+ if resource.Proxmox != nil {
+ add(resource.Proxmox.NodeName,
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ add(resource.Proxmox.ClusterName,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ }
+ if resource.Kubernetes != nil {
+ add(resource.Kubernetes.NodeName,
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ add(resource.Kubernetes.ClusterID,
+ unifiedresources.ResourceRedactionPlatformID,
+ )
+ add(resource.Kubernetes.ClusterName,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ add(resource.Kubernetes.SourceName,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ }
+ if resource.Storage != nil {
+ add(resource.Storage.Path,
+ unifiedresources.ResourceRedactionPath,
+ )
+ }
+
+ add(handoffResource.Name,
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ add(handoffResource.ID,
+ unifiedresources.ResourceRedactionPlatformID,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ add(handoffResource.Node,
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionPlatformID,
+ unifiedresources.ResourceRedactionAlias,
+ )
+ return references
+}
+
func mergeHandoffResourcePolicyContext(handoffContext string, handoffResources []HandoffResource, provider tools.UnifiedResourceProvider) string {
policyContext := buildHandoffResourcePolicyContext(handoffResources, provider)
switch {
diff --git a/internal/ai/chat/service_execute_additional_test.go b/internal/ai/chat/service_execute_additional_test.go
index 0296e5266a..057aea79b8 100644
--- a/internal/ai/chat/service_execute_additional_test.go
+++ b/internal/ai/chat/service_execute_additional_test.go
@@ -530,6 +530,125 @@ func TestService_ExecuteStream_HandoffResourcePolicyContextIsModelOnly(t *testin
}
}
+func TestService_ExecuteStream_OperatorBriefingHandoffHonorsResourcePolicy(t *testing.T) {
+ tmpDir := t.TempDir()
+ store, err := NewSessionStore(tmpDir)
+ if err != nil {
+ t.Fatalf("failed to create session store: %v", err)
+ }
+
+ unifiedProvider := handoffUnifiedProvider{resources: map[unifiedresources.ResourceType][]unifiedresources.Resource{
+ unifiedresources.ResourceTypeVM: {{
+ ID: "vm-100",
+ Type: unifiedresources.ResourceTypeVM,
+ Name: "finance-vm",
+ Status: unifiedresources.StatusWarning,
+ Tags: []string{"pii"},
+ Canonical: &unifiedresources.CanonicalIdentity{
+ DisplayName: "finance-vm",
+ Hostname: "finance-vm",
+ PlatformID: "vm-100",
+ Aliases: []string{"finance-payroll"},
+ },
+ Identity: unifiedresources.ResourceIdentity{
+ Hostnames: []string{"finance-vm"},
+ IPAddresses: []string{"10.0.0.40"},
+ },
+ Proxmox: &unifiedresources.ProxmoxData{
+ NodeName: "pve-secret",
+ },
+ }},
+ }}
+
+ executor := tools.NewPulseToolExecutor(tools.ExecutorConfig{UnifiedResourceProvider: unifiedProvider})
+ var capturedMessages []providers.Message
+ provider := &stubServiceProvider{
+ streamFn: func(ctx context.Context, req providers.ChatRequest, callback providers.StreamCallback) error {
+ capturedMessages = append([]providers.Message(nil), req.Messages...)
+ callback(providers.StreamEvent{
+ Type: "content",
+ Data: providers.ContentEvent{Text: "noted"},
+ })
+ callback(providers.StreamEvent{
+ Type: "done",
+ Data: providers.DoneEvent{InputTokens: 1, OutputTokens: 1},
+ })
+ return nil
+ },
+ }
+ loop := NewAgenticLoop(provider, executor, "system")
+
+ svc := &Service{
+ cfg: &config.AIConfig{ChatModel: "ollama:test"},
+ sessions: store,
+ executor: executor,
+ agenticLoop: loop,
+ provider: provider,
+ unifiedResourceProvider: unifiedProvider,
+ started: true,
+ }
+
+ req := ExecuteRequest{
+ SessionID: "sess-operator-briefing-policy",
+ Prompt: "What happened?",
+ HandoffContext: strings.Join([]string{
+ "[Operator Briefing]",
+ "Briefing Source: Pulse Patrol structured finding",
+ "Resource: finance-vm (vm) [vm-100] on pve-secret",
+ "Current Conclusion: finance-vm on pve-secret saturated CPU during backup.",
+ "Recommended Next Step: Review finance-payroll after backup completion.",
+ "Operator Boundary: Treat Patrol data as product context for explanation and review.",
+ }, "\n"),
+ HandoffResources: []HandoffResource{{
+ ID: "vm-100",
+ Name: "finance-vm",
+ Type: "vm",
+ Node: "pve-secret",
+ }},
+ }
+ if err := svc.ExecuteStream(context.Background(), req, func(StreamEvent) {}); err != nil {
+ t.Fatalf("ExecuteStream failed: %v", err)
+ }
+
+ stored, err := store.GetMessages("sess-operator-briefing-policy")
+ if err != nil {
+ t.Fatalf("GetMessages failed: %v", err)
+ }
+ if len(stored) == 0 {
+ t.Fatal("expected stored messages")
+ }
+ if stored[0].Content != "What happened?" {
+ t.Fatalf("stored user message = %q, want clean prompt", stored[0].Content)
+ }
+ if strings.Contains(stored[0].Content, "[Operator Briefing]") {
+ t.Fatalf("stored user message should not include operator briefing: %q", stored[0].Content)
+ }
+
+ if len(capturedMessages) == 0 {
+ t.Fatal("expected provider messages")
+ }
+ modelUserContent := capturedMessages[len(capturedMessages)-1].Content
+ for _, expected := range []string{
+ "[Operator Briefing]",
+ "Resource: redacted by policy (vm) [redacted by policy] on redacted by policy",
+ "Current Conclusion: redacted by policy on redacted by policy saturated CPU during backup.",
+ "Recommended Next Step: Review redacted by policy after backup completion.",
+ "[Resource Policy Context]",
+ "Resource Policy: virtual machine resource; status warning; local-only context",
+ "Policy Boundary: Resource policy is read-only data-handling context",
+ "User message: What happened?",
+ } {
+ if !strings.Contains(modelUserContent, expected) {
+ t.Fatalf("model user content missing %q: %q", expected, modelUserContent)
+ }
+ }
+ for _, forbidden := range []string{"finance-vm", "vm-100", "pve-secret", "finance-payroll", "10.0.0.40"} {
+ if strings.Contains(modelUserContent, forbidden) {
+ t.Fatalf("model user content leaked governed resource identity %q: %q", forbidden, modelUserContent)
+ }
+ }
+}
+
func TestService_ExecuteStream_HandoffResourceRelationshipContextIsModelOnly(t *testing.T) {
tmpDir := t.TempDir()
store, err := NewSessionStore(tmpDir)
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 16849d75d5..d38e959d5a 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -200,6 +200,7 @@ func TestContract_AssistantFindingContextUsesModelOnlyHandoff(t *testing.T) {
"mergeHandoffResourceRelationshipContext(handoffContext, handoffResources, handoffResourceProvider)",
"mergeHandoffResourceTimelineContext(handoffContext, handoffResources, handoffResourceProvider, s.actionAuditStore, time.Now())",
"handoffContext = mergeHandoffActionContext(handoffContext, handoffActions)",
+ "sanitizeHandoffContextForResourcePolicy(handoffContext, handoffResources, handoffResourceProvider)",
"Action Reference",
"Action State",
"Action Plan Expires At",
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index 1adacf92cc..9fe5c9458a 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -646,6 +646,10 @@ func TestResourcePolicyLabelHelpersUsedByAIConsumers(t *testing.T) {
"unifiedresources.ResourceClusterName(",
"unifiedresources.ResourceIPSummary(",
},
+ filepath.Join("..", "ai", "chat", "service.go"): {
+ "unifiedresources.ResourcePolicyRedactedTextWithReferences(",
+ "unifiedresources.ResourcePolicyReference(",
+ },
filepath.Join("..", "unifiedresources", "unified_ai_adapter.go"): {
"ResourceDisplayName(results[i])",
"ResourceDisplayName(results[j])",
@@ -658,6 +662,8 @@ func TestResourcePolicyLabelHelpersUsedByAIConsumers(t *testing.T) {
"Policy: sensitivity=%s, routing=%s",
"func ResourcePolicyRedactedValue(value string, policy *ResourcePolicy, hints ...ResourceRedactionHint) string",
"func ResourcePolicyRedactedText(value string, resource Resource) string",
+ "func ResourcePolicyRedactedTextWithReferences(value string, resource Resource, references ...ResourcePolicyRedactionReference) string",
+ "func ResourcePolicyReference(value string, hints ...ResourceRedactionHint) ResourcePolicyRedactionReference",
"const ResourcePolicyRedactedLabel = \"redacted by policy\"",
"func ResourceRedactionLabelsFromHints(hints []ResourceRedactionHint) []string",
"func ResourceClusterName(resource Resource) string",
diff --git a/internal/unifiedresources/policy_metadata_test.go b/internal/unifiedresources/policy_metadata_test.go
index e174b40b42..3cd3b14a44 100644
--- a/internal/unifiedresources/policy_metadata_test.go
+++ b/internal/unifiedresources/policy_metadata_test.go
@@ -463,6 +463,41 @@ func TestResourcePolicyRedactedText(t *testing.T) {
}
}
+func TestResourcePolicyRedactedTextWithReferences(t *testing.T) {
+ resource := Resource{
+ ID: "storage:local-zfs",
+ Name: "local-zfs",
+ Type: ResourceTypeStorage,
+ Status: StatusOnline,
+ Storage: &StorageMeta{
+ Path: "/mnt/pve/finance",
+ },
+ Policy: &ResourcePolicy{
+ Sensitivity: ResourceSensitivitySensitive,
+ Routing: ResourceRoutingPolicy{
+ Scope: ResourceRoutingScopeLocalFirst,
+ Redact: []ResourceRedactionHint{ResourceRedactionPath},
+ },
+ },
+ }
+
+ got := ResourcePolicyRedactedTextWithReferences(
+ "finance-dataset uses local-zfs at /mnt/pve/finance on pve-secret",
+ resource,
+ ResourcePolicyReference("finance-dataset", ResourceRedactionAlias),
+ ResourcePolicyReference("local-zfs", ResourceRedactionHostname),
+ ResourcePolicyReference("pve-secret", ResourceRedactionHostname),
+ )
+ for _, raw := range []string{"finance-dataset", "local-zfs", "/mnt/pve/finance", "pve-secret"} {
+ if strings.Contains(got, raw) {
+ t.Fatalf("expected %q to be redacted from %q", raw, got)
+ }
+ }
+ if count := strings.Count(got, ResourcePolicyRedactedLabel); count < 4 {
+ t.Fatalf("expected redaction markers in %q", got)
+ }
+}
+
func TestResourceRedactionLabelsFromHints(t *testing.T) {
got := ResourceRedactionLabelsFromHints([]ResourceRedactionHint{
ResourceRedactionPath,
diff --git a/internal/unifiedresources/policy_presentation.go b/internal/unifiedresources/policy_presentation.go
index befa288582..133e15a65c 100644
--- a/internal/unifiedresources/policy_presentation.go
+++ b/internal/unifiedresources/policy_presentation.go
@@ -264,6 +264,23 @@ func ResourcePolicyRedactedValue(value string, policy *ResourcePolicy, hints ...
return value
}
+// ResourcePolicyRedactionReference describes an additional product-originated
+// resource reference that should follow the same governed prompt-label boundary
+// as canonical resource identifiers.
+type ResourcePolicyRedactionReference struct {
+ Value string
+ Hints []ResourceRedactionHint
+}
+
+// ResourcePolicyReference builds a redaction reference with a defensive copy of
+// the supplied hint list.
+func ResourcePolicyReference(value string, hints ...ResourceRedactionHint) ResourcePolicyRedactionReference {
+ return ResourcePolicyRedactionReference{
+ Value: strings.TrimSpace(value),
+ Hints: append([]ResourceRedactionHint(nil), hints...),
+ }
+}
+
// ResourcePolicyRedactedText replaces exact resource identifiers that the
// canonical resource policy marks for redaction. It is intentionally
// value-based so alert, prompt, and export summaries cannot leak the same raw
@@ -305,6 +322,63 @@ func ResourcePolicyRedactedText(value string, resource Resource) string {
return redacted
}
+// ResourcePolicyRedactedTextWithReferences redacts canonical resource
+// identifiers plus additional structured references supplied by the caller.
+// References represent prompt labels, handoff selectors, or transport fields
+// that identify the same resource but are not guaranteed to be present on the
+// canonical resource itself. When policy requires a governed summary, references
+// are redacted as identity fields even if their individual hint is not listed,
+// matching ResourcePolicyLabel's "safe summary over raw label" contract.
+func ResourcePolicyRedactedTextWithReferences(value string, resource Resource, references ...ResourcePolicyRedactionReference) string {
+ redacted := ResourcePolicyRedactedText(value, resource)
+ if strings.TrimSpace(redacted) == "" || resource.Policy == nil || len(references) == 0 {
+ return redacted
+ }
+
+ candidates := make([]ResourcePolicyRedactionReference, 0, len(references))
+ seen := make(map[string]struct{}, len(references))
+ for _, reference := range references {
+ reference.Value = strings.TrimSpace(reference.Value)
+ if reference.Value == "" || len([]rune(reference.Value)) < 3 {
+ continue
+ }
+ if _, ok := seen[reference.Value]; ok {
+ continue
+ }
+ seen[reference.Value] = struct{}{}
+ reference.Hints = append([]ResourceRedactionHint(nil), reference.Hints...)
+ candidates = append(candidates, reference)
+ }
+ if len(candidates) == 0 {
+ return redacted
+ }
+
+ sort.Slice(candidates, func(i, j int) bool {
+ if len(candidates[i].Value) == len(candidates[j].Value) {
+ return candidates[i].Value < candidates[j].Value
+ }
+ return len(candidates[i].Value) > len(candidates[j].Value)
+ })
+
+ for _, candidate := range candidates {
+ if !resourcePolicyShouldRedactReference(resource.Policy, candidate.Hints...) {
+ continue
+ }
+ redacted = strings.ReplaceAll(redacted, candidate.Value, ResourcePolicyRedactedLabel)
+ }
+ return redacted
+}
+
+func resourcePolicyShouldRedactReference(policy *ResourcePolicy, hints ...ResourceRedactionHint) bool {
+ if policy == nil {
+ return false
+ }
+ if ResourcePolicyRequiresGovernedSummary(policy) {
+ return true
+ }
+ return ResourcePolicyRedacts(policy, hints...)
+}
+
// ResourceDisplayName returns the canonical resource display name fallback.
func ResourceDisplayName(resource Resource) string {
if resource.Canonical != nil {