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.

Expose resource intelligence policy posture

rcourtman7e42773c2f5e
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 8fb7ca620c..11d3141e9a 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -171,6 +171,9 @@ The same unified intelligence summary now also surfaces a canonical policy
posture snapshot derived from unified resources, so sensitivity, routing, and
redaction counts stay aligned with the governed resource model that the
runtime uses for prompt export and context rendering.
+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.
The shared AI resource and infrastructure prompt contexts should also surface
the same canonical recent changes section before any patrol-local fallback so
the model sees the same timeline entries that power the resource API and
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 5cafbe3f7c..9aa252b7e0 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -78,6 +78,7 @@ Own canonical runtime payload shapes between backend and frontend.
7. Route canonical AI intelligence summary and resource-intelligence reads through `frontend-modern/src/api/ai.ts`, `frontend-modern/src/stores/aiIntelligence.ts`, `frontend-modern/src/pages/AIIntelligence.tsx`, `internal/api/ai_handlers.go`, and `internal/api/contract_test.go` together so the summary card, store state, and backend payload stay aligned on one governed surface, including the canonical recent-changes slice
and the shared `frontend-modern/src/utils/resourceChangePresentation.ts` formatter used by the summary page and resource drawer, so canonical change wording does not drift across surfaces
and the canonical policy-posture snapshot derived from unified resources, so sensitivity, routing, and redaction counts stay owned by the same AI summary contract instead of being reconstructed as a page-local governance rollup
+ and the resource-intelligence payload carried by the drawer AI card, so the governed posture snapshot remains visible on the resource-detail surface without introducing a separate posture endpoint
8. Route frontend API-client parsed error propagation, API-error-status fallback handling, allowed-status handling, custom status-specific error handling, command-trigger success envelope handling, shared response parsing pipelines, missing-resource lookup handling, metadata CRUD routing, stream event consumption, response status, collection normalization, scalar payload coercion, and structured error normalization through canonical shared helpers under `frontend-modern/src/api/`
9. Add or change API token scope, assignment, and revocation presentation through `frontend-modern/src/components/Settings/APITokenManager.tsx`
10. Add or change infrastructure operations token generation, lookup, assignment, and reporting/install presentation through `frontend-modern/src/components/Settings/InfrastructureOperationsController.tsx`
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 71de1d4289..038f00685d 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -92,6 +92,9 @@ That Patrol summary card now also includes the canonical data-governance
posture snapshot from the shared AI summary payload, so the visible page can
show the same sensitivity, routing, and redaction distribution that the
runtime derives from unified resources.
+The resource drawer now carries the same canonical posture snapshot through
+the resource-intelligence payload, so the resource-level AI card can show the
+org posture context without introducing a separate posture endpoint.
The Patrol page and resource drawer now also share the canonical
`frontend-modern/src/utils/resourceChangePresentation.ts` formatter so
recent-change kind and headline wording stays aligned wherever the canonical
diff --git a/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx b/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx
index 6e6ac038af..10a8198e5d 100644
--- a/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx
+++ b/frontend-modern/src/components/Infrastructure/ResourceDetailDrawer.tsx
@@ -5,6 +5,9 @@ import type {
ResourceChangeKind,
ResourceChangeSourceAdapter,
ResourceChangeSourceType,
+ ResourceRedactionHint,
+ ResourceRoutingScope,
+ ResourceSensitivity,
} from '@/types/resource';
import { getDisplayName } from '@/types/resource';
import { formatUptime, formatRelativeTime, formatAbsoluteTime } from '@/utils/format';
@@ -49,6 +52,7 @@ import { buildInfrastructurePath } from '@/routing/resourceLinks';
import {
getResourcePolicyBadges,
getResourcePolicyRedactionLabels,
+ getResourceRedactionHintLabel,
getResourceRoutingScopeLabel,
getResourceSensitivityLabel,
} from '@/utils/resourcePolicyPresentation';
@@ -112,6 +116,23 @@ const timelineSourceAdapterOptions: Array<{ label: string; value: ResourceChange
{ label: 'Ops agent', value: 'agent:ops-helper' },
];
+const policySensitivityOrder: ResourceSensitivity[] = [
+ 'public',
+ 'internal',
+ 'sensitive',
+ 'restricted',
+];
+
+const policyRoutingOrder: ResourceRoutingScope[] = ['cloud-summary', 'local-first', 'local-only'];
+
+const policyRedactionOrder: ResourceRedactionHint[] = [
+ 'hostname',
+ 'ip-address',
+ 'platform-id',
+ 'alias',
+ 'path',
+];
+
const DrawerContent: Component<ResourceDetailDrawerProps> = (props) => {
type DrawerTab =
| 'overview'
@@ -275,6 +296,7 @@ const DrawerContent: Component<ResourceDetailDrawerProps> = (props) => {
},
{ initialValue: null as ResourceIntelligence | null },
);
+ const policyPosture = createMemo(() => resourceIntelligence()?.policy_posture);
const timelineFacetRequest = createMemo(() => {
const id = resourceFacetId();
if (!id) return null;
@@ -871,6 +893,65 @@ const DrawerContent: Component<ResourceDetailDrawerProps> = (props) => {
</div>
</div>
</Show>
+ <Show when={policyPosture()}>
+ {(posture) => (
+ <div class="rounded border border-border-subtle bg-base px-2 py-1.5">
+ <div class="text-[10px] uppercase tracking-wide text-muted">
+ Policy posture
+ </div>
+ <div class="mt-0.5 text-[11px] text-base-content">
+ {posture().total_resources} governed resources
+ </div>
+ <div class="mt-2 grid grid-cols-2 gap-1.5">
+ <For each={policySensitivityOrder}>
+ {(sensitivity) => (
+ <div class="rounded bg-surface px-2 py-1">
+ <div class="text-[9px] uppercase tracking-wide text-muted">
+ {getResourceSensitivityLabel(sensitivity)}
+ </div>
+ <div class="font-medium text-base-content">
+ {posture().sensitivity_counts?.[sensitivity] ?? 0}
+ </div>
+ </div>
+ )}
+ </For>
+ </div>
+ <div class="mt-2 grid grid-cols-3 gap-1.5">
+ <For each={policyRoutingOrder}>
+ {(scope) => (
+ <div class="rounded bg-surface px-2 py-1">
+ <div class="text-[9px] uppercase tracking-wide text-muted">
+ {getResourceRoutingScopeLabel(scope)}
+ </div>
+ <div class="font-medium text-base-content">
+ {posture().routing_counts?.[scope] ?? 0}
+ </div>
+ </div>
+ )}
+ </For>
+ </div>
+ <Show
+ when={policyRedactionOrder.some(
+ (hint) => (posture().redaction_counts?.[hint] ?? 0) > 0,
+ )}
+ >
+ <div class="mt-2 flex flex-wrap gap-1">
+ <For each={policyRedactionOrder}>
+ {(hint) => {
+ const count = posture().redaction_counts?.[hint] ?? 0;
+ if (!count) return null;
+ return (
+ <span class="inline-flex items-center rounded bg-surface-alt px-1.5 py-0.5 text-[10px]">
+ {getResourceRedactionHintLabel(hint)} {count}
+ </span>
+ );
+ }}
+ </For>
+ </div>
+ </Show>
+ </div>
+ )}
+ </Show>
</div>
</div>
)}
diff --git a/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.identity-runtime.test.tsx b/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.identity-runtime.test.tsx
index 1c45cbd55e..593d743edb 100644
--- a/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.identity-runtime.test.tsx
+++ b/frontend-modern/src/components/Infrastructure/__tests__/ResourceDetailDrawer.identity-runtime.test.tsx
@@ -54,6 +54,20 @@ vi.mock('@/api/ai', () => ({
reason: 'Updated canonical config',
},
],
+ policy_posture: {
+ total_resources: 2,
+ sensitivity_counts: {
+ public: 1,
+ internal: 1,
+ },
+ routing_counts: {
+ 'cloud-summary': 1,
+ 'local-first': 1,
+ },
+ redaction_counts: {
+ hostname: 1,
+ },
+ },
note_count: 3,
}),
},
@@ -297,7 +311,11 @@ describe('ResourceDetailDrawer runtime and identity cards', () => {
expect(getByText(/A · 92\/100/)).toBeInTheDocument();
expect(getByText('Recent Changes')).toBeInTheDocument();
- expect(getByText('1')).toBeInTheDocument();
+ expect(getByText('Recent Changes').parentElement).toHaveTextContent('1');
+ expect(getByText('Policy posture')).toBeInTheDocument();
+ expect(getByText('2 governed resources')).toBeInTheDocument();
+ expect(getByText('Public')).toBeInTheDocument();
+ expect(getByText('Cloud Summary')).toBeInTheDocument();
const latestChange = getByText('Latest canonical change').parentElement;
expect(latestChange).not.toBeNull();
expect(latestChange).toHaveTextContent('Config update');
diff --git a/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts b/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts
index 7dcea5b103..803f7e4e7b 100644
--- a/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts
+++ b/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts
@@ -132,6 +132,7 @@ describe('aiIntelligenceStore', () => {
},
});
expect(aiIntelligenceStore.intelligenceSummary?.recent_changes).toHaveLength(1);
+ expect(aiIntelligenceStore.intelligenceSummary?.policy_posture?.routing_counts?.['local-only']).toBe(1);
});
it('treats queued fixes without a live approval as findings needing attention', async () => {
diff --git a/frontend-modern/src/types/aiIntelligence.ts b/frontend-modern/src/types/aiIntelligence.ts
index 2e6541190b..8ae74636cb 100644
--- a/frontend-modern/src/types/aiIntelligence.ts
+++ b/frontend-modern/src/types/aiIntelligence.ts
@@ -113,5 +113,6 @@ export interface ResourceIntelligence {
resource_type?: string;
health: IntelligenceHealthScore;
recent_changes?: ResourceChange[];
+ policy_posture?: IntelligencePolicyPostureSummary;
note_count: number;
}
diff --git a/internal/ai/intelligence.go b/internal/ai/intelligence.go
index e82eb44a26..7c4db38d94 100644
--- a/internal/ai/intelligence.go
+++ b/internal/ai/intelligence.go
@@ -70,6 +70,7 @@ type ResourceIntelligence struct {
Anomalies []AnomalyReport `json:"anomalies,omitempty"`
RecentIncidents []*memory.Incident `json:"recent_incidents,omitempty"`
RecentChanges []unifiedresources.ResourceChange `json:"recent_changes,omitempty"`
+ PolicyPosture *PolicyPostureSummary `json:"policy_posture,omitempty"`
Knowledge *knowledge.GuestKnowledge `json:"knowledge,omitempty"`
NoteCount int `json:"note_count"`
}
@@ -305,6 +306,7 @@ func (i *Intelligence) GetSummary() *IntelligenceSummary {
// GetResourceIntelligence returns aggregated intelligence for a specific resource
func (i *Intelligence) GetResourceIntelligence(resourceID string) *ResourceIntelligence {
i.mu.RLock()
+ unifiedResourceProvider := i.unifiedResourceProvider
defer i.mu.RUnlock()
intel := &ResourceIntelligence{
@@ -359,6 +361,12 @@ func (i *Intelligence) GetResourceIntelligence(resourceID string) *ResourceIntel
intel.RecentChanges = recentChanges
}
+ if unifiedResourceProvider != nil {
+ intel.PolicyPosture = summarizePolicyPosture(
+ normalizeUnifiedResourceContextSlice(unifiedResourceProvider.GetAll()),
+ )
+ }
+
// Knowledge
if i.knowledge != nil {
if k, err := i.knowledge.GetKnowledge(resourceID); err == nil && k != nil {
diff --git a/internal/ai/intelligence_coverage_test.go b/internal/ai/intelligence_coverage_test.go
index 4305647b66..a22b519ace 100644
--- a/internal/ai/intelligence_coverage_test.go
+++ b/internal/ai/intelligence_coverage_test.go
@@ -625,6 +625,19 @@ func TestIntelligence_GetResourceIntelligence_WithAllSubsystems(t *testing.T) {
_ = knowledgeStore.SaveNote("vm-intel", "vm-intel", "vm", "general", "Note", "Content")
intel.SetSubsystems(findings, patternDetector, correlationDetector, baselineStore, incidentStore, knowledgeStore, nil, nil)
+ intel.SetUnifiedResourceProvider(&mockUnifiedResourceProvider{
+ getAllFunc: func() []ur.Resource {
+ return []ur.Resource{
+ {ID: "public-1", Type: ur.ResourceTypeVM, Tags: []string{"public"}},
+ {
+ ID: "internal-1",
+ Type: ur.ResourceTypeAgent,
+ Agent: &ur.AgentData{Hostname: "agent-1"},
+ Status: ur.StatusOnline,
+ },
+ }
+ },
+ })
canonicalStore := ur.NewMemoryStore()
if err := canonicalStore.RecordChange(ur.ResourceChange{
ID: "change-intel",
@@ -664,6 +677,15 @@ func TestIntelligence_GetResourceIntelligence_WithAllSubsystems(t *testing.T) {
if res.RecentChanges[0].Kind != ur.ChangeRestart {
t.Fatalf("expected restart change kind, got %s", res.RecentChanges[0].Kind)
}
+ if res.PolicyPosture == nil {
+ t.Fatal("expected policy posture summary")
+ }
+ if res.PolicyPosture.TotalResources != 2 {
+ t.Fatalf("expected 2 governed resources, got %d", res.PolicyPosture.TotalResources)
+ }
+ if got := res.PolicyPosture.SensitivityCounts[ur.ResourceSensitivityPublic]; got != 1 {
+ t.Fatalf("expected 1 public resource, got %d", got)
+ }
if res.Knowledge == nil || res.NoteCount == 0 {
t.Error("expected knowledge")
}
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 6a8fb60e6a..5bd1cf468f 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -297,6 +297,12 @@ func TestContract_ResourceIntelligenceIncludesRecentChanges(t *testing.T) {
}); err != nil {
t.Fatalf("record canonical change: %v", err)
}
+ svc.SetUnifiedResourceProvider(&stubUnifiedResourceProvider{
+ resources: []unifiedresources.Resource{
+ {ID: "public-1", Type: unifiedresources.ResourceTypeVM, Tags: []string{"public"}},
+ {ID: "internal-1", Type: unifiedresources.ResourceTypeAgent, Agent: &unifiedresources.AgentData{Hostname: "agent-1"}},
+ },
+ })
setUnexportedField(t, svc, "resourceExportStore", canonicalStore)
setUnexportedField(t, svc.GetPatrolService(), "aiService", svc)
@@ -321,6 +327,13 @@ func TestContract_ResourceIntelligenceIncludesRecentChanges(t *testing.T) {
if len(recentChanges) != 1 {
t.Fatalf("expected 1 recent change, got %d", len(recentChanges))
}
+ policyPosture, ok := payload["policy_posture"].(map[string]interface{})
+ if !ok {
+ t.Fatalf("expected policy_posture object in response, got %T", payload["policy_posture"])
+ }
+ if got := int(policyPosture["total_resources"].(float64)); got != 2 {
+ t.Fatalf("expected total_resources=2, got %d", got)
+ }
}
func TestContract_IntelligenceSummaryIncludesRecentChanges(t *testing.T) {