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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Add unified resource facet bundle endpoint
rcourtmandc63f866484d
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 30cba95218..4ad074faea 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -1009,4 +1009,7 @@ policy-aware resource metadata. Agent lifecycle and fleet-control surfaces mayconsume canonical `policy` and `aiSafeSummary` fields from unified resourcepayloads when they need resource context, but they must not fork their ownsensitivity-classification or local-vs-cloud routing heuristics on the same-runtime boundary.+runtime boundary. The same shared resource boundary now also owns the canonical+facet-bundle read path for capabilities, relationships, and timeline history,+so fleet lifecycle surfaces that open resource drawers must continue to consume+the backend bundle instead of reassembling a local multi-call summary.diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex c57b182c37..cc0f50dca0 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -72,7 +72,7 @@ Own canonical runtime payload shapes between backend and frontend.3. Add dedicated contract tests for new stable payloads4. 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 heuristic5. Route unified-resource action, lifecycle, and export audit reads through `internal/api/activity_audit_handlers.go`, `internal/api/router_routes_licensing.go`, and `internal/api/contract_test.go` together so the control-plane execution trail stays on a governed API contract instead of a store-only shape-6. Route dedicated unified-resource capability, relationship, and timeline facet reads through `frontend-modern/src/api/resources.ts`, `internal/api/resources.go`, and `internal/api/contract_test.go` together so the backend facet contract and the frontend client stay aligned on one governed surface, including the backend-provided facet counts needed to distinguish loaded slices from total history+6. Route dedicated unified-resource capability, relationship, timeline, and facet-bundle reads through `frontend-modern/src/api/resources.ts`, `internal/api/resources.go`, and `internal/api/contract_test.go` together so the backend facet contract and the frontend client stay aligned on one governed surface, including the backend-provided facet counts needed to distinguish loaded slices from total history7. 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/`8. Add or change API token scope, assignment, and revocation presentation through `frontend-modern/src/components/Settings/APITokenManager.tsx`9. 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/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 871b9c0d27..e0d8b13692 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -656,4 +656,8 @@ That same shared `internal/api/` resource boundary now also carries governedpolicy-aware metadata. Storage and recovery consumers that read canonicalresource payloads must preserve backend-derived `policy` and `aiSafeSummary`fields for storage, backup, and data-bearing resources instead of rebuilding-their own sensitivity or routing guesses in page-local presentation code.+their own sensitivity or routing guesses in page-local presentation code. That+same boundary now also owns the backend facet-bundle route for capability,+relationship, and timeline history reads, so storage and recovery surfaces+must continue to consume the shared bundle rather than issuing separate local+resource-detail fetches.diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex e7cc701322..7d12b57495 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -181,11 +181,12 @@ rows, so the unified consumer surface must remain consistent across the fulltable instead of diverging by resource class. The same facet summary now alsoappears in the resource drawer's runtime overview card through a shared`ResourceFacetSummary` component, so table and detail views stay aligned on a-single canonical rendering path for the resource graph counts.-The drawer's shared facet bundle also preserves the backend counts for the-loaded capabilities, relationships, and timeline slice, so the overview card-and history summary can report the total facet history instead of collapsing to-the currently loaded page when the timeline endpoint is paginated.+single canonical rendering path for the resource graph counts. The drawer now+fetches those facets through one backend bundle endpoint, and that shared+facet bundle preserves backend counts for capabilities, relationships, and the+timeline slice so the overview card and history summary can report the total+facet history instead of collapsing to the currently loaded page when the+timeline endpoint is paginated.The Connected infrastructure settings surface now also depends on a backendowned `connectedInfrastructure` projection derived from unified resources plusreporting-ignore state. That projection is now also the only v6 clientdiff --git a/frontend-modern/src/api/__tests__/resources.test.ts b/frontend-modern/src/api/__tests__/resources.test.tsindex 3608a8f846..4c006e1241 100644--- a/frontend-modern/src/api/__tests__/resources.test.ts+++ b/frontend-modern/src/api/__tests__/resources.test.ts@@ -31,57 +31,38 @@ describe('ResourceAPI', () => {});it('fetches the resource history bundle from the dedicated facet endpoints', async () => {- vi.mocked(apiFetchJSON)- .mockResolvedValueOnce({- resourceId: 'vm:42',- capabilities: [{ name: 'restart' }],- count: 1,- } as any)- .mockResolvedValueOnce({- resourceId: 'vm:42',- relationships: [{ sourceId: 'node:1', targetId: 'vm:42' }],- count: 1,- } as any)- .mockResolvedValueOnce({- resourceId: 'vm:42',- recentChanges: [{ id: 'change-1' }],- count: 1,- } as any);+ vi.mocked(apiFetchJSON).mockResolvedValueOnce({+ resourceId: 'vm:42',+ capabilities: [{ name: 'restart' }],+ relationships: [{ sourceId: 'node:1', targetId: 'vm:42' }],+ recentChanges: [{ id: 'change-1' }],+ counts: {+ capabilities: 1,+ relationships: 1,+ recentChanges: 3,+ },+ } as any);const result = await ResourceAPI.getFacetBundle('vm:42', {since: '2026-03-18T12:00:00Z',limit: 25,});- expect(apiFetchJSON).toHaveBeenNthCalledWith(- 1,- '/api/resources/vm%3A42/capabilities',- {- cache: 'no-store',- },- );- expect(apiFetchJSON).toHaveBeenNthCalledWith(- 2,- '/api/resources/vm%3A42/relationships',- {- cache: 'no-store',- },- );- expect(apiFetchJSON).toHaveBeenNthCalledWith(- 3,- '/api/resources/vm%3A42/timeline?since=2026-03-18T12%3A00%3A00.000Z&limit=25',+ expect(apiFetchJSON).toHaveBeenCalledWith(+ '/api/resources/vm%3A42/facets?since=2026-03-18T12%3A00%3A00.000Z&limit=25',{cache: 'no-store',},);expect(result).toEqual({+ resourceId: 'vm:42',capabilities: [{ name: 'restart' }],relationships: [{ sourceId: 'node:1', targetId: 'vm:42' }],recentChanges: [{ id: 'change-1' }],counts: {capabilities: 1,relationships: 1,- recentChanges: 1,+ recentChanges: 3,},});});diff --git a/frontend-modern/src/api/resources.ts b/frontend-modern/src/api/resources.tsindex 5b696f3033..5338b0db92 100644--- a/frontend-modern/src/api/resources.ts+++ b/frontend-modern/src/api/resources.ts@@ -88,21 +88,8 @@ export class ResourceAPI {resourceId: string,options?: ResourceTimelineQueryOptions,): Promise<ResourceFacetBundle> {- const [capabilities, relationships, recentChanges] = await Promise.all([- ResourceAPI.getCapabilities(resourceId),- ResourceAPI.getRelationships(resourceId),- ResourceAPI.getTimeline(resourceId, options),- ]);-- return {- capabilities: capabilities.capabilities ?? [],- relationships: relationships.relationships ?? [],- recentChanges: recentChanges.recentChanges ?? [],- counts: {- capabilities: capabilities.count ?? 0,- relationships: relationships.count ?? 0,- recentChanges: recentChanges.count ?? 0,- },- };+ return fetchFacet<ResourceFacetBundle>(+ `${buildFacetPath(resourceId, 'facets')}${buildTimelineQuery(options)}`,+ );}}diff --git a/frontend-modern/src/components/Infrastructure/__tests__/UnifiedResourceTable.performance.contract.test.tsx b/frontend-modern/src/components/Infrastructure/__tests__/UnifiedResourceTable.performance.contract.test.tsxindex 757c526c76..6ac096a190 100644--- a/frontend-modern/src/components/Infrastructure/__tests__/UnifiedResourceTable.performance.contract.test.tsx+++ b/frontend-modern/src/components/Infrastructure/__tests__/UnifiedResourceTable.performance.contract.test.tsx@@ -148,6 +148,11 @@ describe('UnifiedResourceTable performance contract', () => {lastSeenAt: '2026-03-18T12:05:00Z',},]}+ counts={{+ capabilities: 1,+ relationships: 1,+ recentChanges: 3,+ }}recentChanges={[{id: 'change-1',@@ -163,7 +168,7 @@ describe('UnifiedResourceTable performance contract', () => {expect(getByText('Capabilities 1')).toBeInTheDocument();expect(getByText('Relationships 1')).toBeInTheDocument();- expect(getByText('Timeline 1')).toBeInTheDocument();+ expect(getByText('Timeline 3')).toBeInTheDocument();});it('renders facet summary badges without changing the Profile S row budget', async () => {diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 1730dcc3e3..b099a517a7 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -3712,6 +3712,116 @@ func TestContract_ResourceTimelineJSONSnapshot(t *testing.T) {assertJSONSnapshot(t, got, want)}+func TestContract_ResourceFacetsJSONSnapshot(t *testing.T) {+ now := time.Date(2026, 3, 18, 17, 0, 0, 0, time.UTC)+ payload := struct {+ ResourceID string `json:"resourceId"`+ Capabilities []unifiedresources.ResourceCapability `json:"capabilities"`+ Relationships []unifiedresources.ResourceRelationship `json:"relationships"`+ RecentChanges []unifiedresources.ResourceChange `json:"recentChanges"`+ Counts struct {+ Capabilities int `json:"capabilities"`+ Relationships int `json:"relationships"`+ RecentChanges int `json:"recentChanges"`+ } `json:"counts"`+ }{+ ResourceID: "vm:42",+ Capabilities: []unifiedresources.ResourceCapability{+ {+ Name: "restart",+ Type: unifiedresources.CapabilityTypeCommon,+ Description: "Restart the VM",+ MinimumApprovalLevel: unifiedresources.ApprovalAdmin,+ },+ },+ Relationships: []unifiedresources.ResourceRelationship{+ {+ SourceID: "vm:42",+ TargetID: "node-1",+ Type: unifiedresources.RelRunsOn,+ Confidence: 1,+ Active: true,+ Discoverer: "proxmox_adapter",+ ObservedAt: now,+ LastSeenAt: now,+ },+ },+ RecentChanges: []unifiedresources.ResourceChange{+ {+ ID: "chg-42",+ ResourceID: "vm:42",+ ObservedAt: now,+ OccurredAt: &now,+ Kind: unifiedresources.ChangeStateTransition,+ From: "offline",+ To: "online",+ SourceType: unifiedresources.SourcePlatformEvent,+ SourceAdapter: unifiedresources.AdapterProxmox,+ Confidence: unifiedresources.ConfidenceHigh,+ },+ },+ Counts: struct {+ Capabilities int `json:"capabilities"`+ Relationships int `json:"relationships"`+ RecentChanges int `json:"recentChanges"`+ }{+ Capabilities: 1,+ Relationships: 1,+ RecentChanges: 3,+ },+ }++ got, err := json.Marshal(payload)+ if err != nil {+ t.Fatalf("marshal resource facets response: %v", err)+ }++ const want = `{+ "resourceId":"vm:42",+ "capabilities":[+ {+ "name":"restart",+ "type":"common",+ "description":"Restart the VM",+ "minimumApprovalLevel":"admin"+ }+ ],+ "relationships":[+ {+ "sourceId":"vm:42",+ "targetId":"node-1",+ "type":"runs_on",+ "confidence":1,+ "active":true,+ "discoverer":"proxmox_adapter",+ "observedAt":"2026-03-18T17:00:00Z",+ "lastSeenAt":"2026-03-18T17:00:00Z"+ }+ ],+ "recentChanges":[+ {+ "id":"chg-42",+ "observedAt":"2026-03-18T17:00:00Z",+ "occurredAt":"2026-03-18T17:00:00Z",+ "resourceId":"vm:42",+ "kind":"state_transition",+ "from":"offline",+ "to":"online",+ "sourceType":"platform_event",+ "sourceAdapter":"proxmox_adapter",+ "confidence":"high"+ }+ ],+ "counts":{+ "capabilities":1,+ "relationships":1,+ "recentChanges":3+ }+ }`++ assertJSONSnapshot(t, got, want)+}+func TestContract_UnifiedActionAuditsJSONSnapshot(t *testing.T) {now := time.Date(2026, 3, 18, 16, 0, 0, 0, time.UTC)payload := struct {diff --git a/internal/api/resources.go b/internal/api/resources.goindex 0c14ffc8b7..01e58ffcec 100644--- a/internal/api/resources.go+++ b/internal/api/resources.go@@ -277,8 +277,26 @@ func (h *ResourceHandlers) HandleGetResource(w http.ResponseWriter, r *http.Requjson.NewEncoder(w).Encode(resourceCopy)}+type resourceFacetCountsResponse struct {+ Capabilities int `json:"capabilities"`+ Relationships int `json:"relationships"`+ RecentChanges int `json:"recentChanges"`+}++type resourceFacetBundleResponse struct {+ ResourceID string `json:"resourceId"`+ Capabilities []unified.ResourceCapability `json:"capabilities"`+ Relationships []unified.ResourceRelationship `json:"relationships"`+ RecentChanges []unified.ResourceChange `json:"recentChanges"`+ Counts resourceFacetCountsResponse `json:"counts"`+}+// HandleResourceRoutes dispatches nested resource routes.func (h *ResourceHandlers) HandleResourceRoutes(w http.ResponseWriter, r *http.Request) {+ if strings.HasSuffix(r.URL.Path, "/facets") {+ h.HandleGetResourceFacets(w, r)+ return+ }if strings.HasSuffix(r.URL.Path, "/capabilities") {h.HandleGetResourceCapabilities(w, r)return@@ -314,6 +332,93 @@ func (h *ResourceHandlers) HandleResourceRoutes(w http.ResponseWriter, r *http.Rh.HandleGetResource(w, r)}+// HandleGetResourceFacets handles GET /api/resources/{id}/facets.+func (h *ResourceHandlers) HandleGetResourceFacets(w http.ResponseWriter, r *http.Request) {+ if r.Method != http.MethodGet {+ http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)+ return+ }++ orgID := GetOrgID(r.Context())+ registry, err := h.buildRegistry(orgID)+ if err != nil {+ http.Error(w, sanitizeErrorForClient(err, "Internal server error"), http.StatusInternalServerError)+ return+ }+ store, err := h.getStore(orgID)+ if err != nil {+ http.Error(w, sanitizeErrorForClient(err, "Internal server error"), http.StatusInternalServerError)+ return+ }++ resourceID := strings.TrimPrefix(r.URL.Path, "/api/resources/")+ resourceID = strings.TrimSuffix(resourceID, "/facets")+ resourceID = strings.TrimSuffix(resourceID, "/")+ resourceID = unified.CanonicalResourceID(resourceID)+ if resourceID == "" {+ http.Error(w, "Resource ID required", http.StatusBadRequest)+ return+ }++ resource, ok := registry.Get(resourceID)+ if !ok {+ http.Error(w, "Resource not found", http.StatusNotFound)+ return+ }++ since := time.Time{}+ if raw := strings.TrimSpace(r.URL.Query().Get("since")); raw != "" {+ parsed, parseErr := time.Parse(time.RFC3339, raw)+ if parseErr != nil {+ http.Error(w, "Invalid since value", http.StatusBadRequest)+ return+ }+ since = parsed.UTC()+ }+ limit := 25+ if raw := strings.TrimSpace(r.URL.Query().Get("limit")); raw != "" {+ parsed, parseErr := strconv.Atoi(raw)+ if parseErr != nil || parsed <= 0 {+ http.Error(w, "Invalid limit value", http.StatusBadRequest)+ return+ }+ limit = parsed+ }++ recentChanges, err := store.GetRecentChanges(resourceID, since, limit)+ if err != nil {+ http.Error(w, sanitizeErrorForClient(err, "Internal server error"), http.StatusInternalServerError)+ return+ }+ changeCount, err := store.CountRecentChanges(resourceID, since)+ if err != nil {+ http.Error(w, sanitizeErrorForClient(err, "Internal server error"), http.StatusInternalServerError)+ return+ }++ capabilities := resource.Capabilities+ if capabilities == nil {+ capabilities = []unified.ResourceCapability{}+ }+ relationships := resource.Relationships+ if relationships == nil {+ relationships = []unified.ResourceRelationship{}+ }++ w.Header().Set("Content-Type", "application/json")+ json.NewEncoder(w).Encode(resourceFacetBundleResponse{+ ResourceID: resourceID,+ Capabilities: capabilities,+ Relationships: relationships,+ RecentChanges: recentChanges,+ Counts: resourceFacetCountsResponse{+ Capabilities: len(capabilities),+ Relationships: len(relationships),+ RecentChanges: changeCount,+ },+ })+}+// HandleGetChildren handles GET /api/resources/{id}/children.func (h *ResourceHandlers) HandleGetChildren(w http.ResponseWriter, r *http.Request) {if r.Method != http.MethodGet {@@ -512,12 +617,17 @@ func (h *ResourceHandlers) HandleGetResourceTimeline(w http.ResponseWriter, r *hhttp.Error(w, sanitizeErrorForClient(err, "Internal server error"), http.StatusInternalServerError)return}+ changeCount, err := store.CountRecentChanges(resourceID, since)+ if err != nil {+ http.Error(w, sanitizeErrorForClient(err, "Internal server error"), http.StatusInternalServerError)+ return+ }w.Header().Set("Content-Type", "application/json")json.NewEncoder(w).Encode(map[string]any{"resourceId": resourceID,"recentChanges": changes,- "count": len(changes),+ "count": changeCount,})}diff --git a/internal/api/resources_test.go b/internal/api/resources_test.goindex 0cfb80d07d..c3d6e7dab9 100644--- a/internal/api/resources_test.go+++ b/internal/api/resources_test.go@@ -3,6 +3,7 @@ package apiimport ("bytes""encoding/json"+ "fmt""net/http""net/http/httptest""strings"@@ -912,6 +913,49 @@ func TestResourceGetFacetsAndTimeline(t *testing.T) {}); err != nil {t.Fatalf("RecordChange: %v", err)}+ for i, offset := range []time.Duration{2 * time.Minute, 4 * time.Minute} {+ if err := store.RecordChange(unified.ResourceChange{+ ID: fmt.Sprintf("chg-42-extra-%d", i+1),+ ResourceID: "vm:42",+ ObservedAt: now.Add(-offset),+ Kind: unified.ChangeAnomaly,+ SourceType: unified.SourcePulseDiff,+ SourceAdapter: unified.AdapterProxmox,+ Confidence: unified.ConfidenceMedium,+ Reason: "history backfill",+ }); err != nil {+ t.Fatalf("RecordChange extra %d: %v", i+1, err)+ }+ }++ t.Run("facets", func(t *testing.T) {+ rec := httptest.NewRecorder()+ req := httptest.NewRequest(http.MethodGet, "/api/resources/vm:42/facets?limit=1", nil)+ h.HandleResourceRoutes(rec, req)+ if rec.Code != http.StatusOK {+ t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())+ }+ var payload struct {+ ResourceID string `json:"resourceId"`+ Capabilities []unified.ResourceCapability `json:"capabilities"`+ Relationships []unified.ResourceRelationship `json:"relationships"`+ RecentChanges []unified.ResourceChange `json:"recentChanges"`+ Counts struct {+ Capabilities int `json:"capabilities"`+ Relationships int `json:"relationships"`+ RecentChanges int `json:"recentChanges"`+ } `json:"counts"`+ }+ if err := json.NewDecoder(rec.Body).Decode(&payload); err != nil {+ t.Fatalf("decode facets: %v", err)+ }+ if payload.ResourceID != "vm:42" || payload.Counts.RecentChanges != 3 || len(payload.RecentChanges) != 1 {+ t.Fatalf("unexpected facets payload: %#v", payload)+ }+ if payload.Counts.Capabilities != 1 || payload.Counts.Relationships != 1 {+ t.Fatalf("unexpected facet counts: %#v", payload.Counts)+ }+ })t.Run("capabilities", func(t *testing.T) {rec := httptest.NewRecorder()@@ -968,7 +1012,7 @@ func TestResourceGetFacetsAndTimeline(t *testing.T) {if err := json.NewDecoder(rec.Body).Decode(&payload); err != nil {t.Fatalf("decode timeline: %v", err)}- if payload.ResourceID != "vm:42" || payload.Count != 1 || len(payload.RecentChanges) != 1 {+ if payload.ResourceID != "vm:42" || payload.Count != 3 || len(payload.RecentChanges) != 3 {t.Fatalf("unexpected timeline payload: %#v", payload)}if payload.RecentChanges[0].ID != "chg-42" {diff --git a/internal/api/route_inventory_test.go b/internal/api/route_inventory_test.goindex 2d153ef568..8b56832a61 100644--- a/internal/api/route_inventory_test.go+++ b/internal/api/route_inventory_test.go@@ -353,6 +353,7 @@ var allRouteAllowlist = []string{"/api/resources/k8s/namespaces","/api/resources/stats","/api/resources/",+ "/api/resources/{id}/facets","/api/resources/{id}/capabilities","/api/resources/{id}/relationships","/api/resources/{id}/timeline",diff --git a/internal/api/router_routes_monitoring.go b/internal/api/router_routes_monitoring.goindex 87f1b91aa7..ceab2bb454 100644--- a/internal/api/router_routes_monitoring.go+++ b/internal/api/router_routes_monitoring.go@@ -33,6 +33,7 @@ func (r *Router) registerMonitoringResourceRoutes(r.mux.HandleFunc("/api/resources/storage-summary", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleStorageSummary)))r.mux.HandleFunc("/api/resources/stats", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleStats)))r.mux.HandleFunc("/api/resources/k8s/namespaces", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleK8sNamespaces)))+ r.mux.HandleFunc("/api/resources/{id}/facets", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleGetResourceFacets)))r.mux.HandleFunc("/api/resources/{id}/capabilities", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleGetResourceCapabilities)))r.mux.HandleFunc("/api/resources/{id}/relationships", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleGetResourceRelationships)))r.mux.HandleFunc("/api/resources/{id}/timeline", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.resourceHandlers.HandleGetResourceTimeline)))diff --git a/internal/unifiedresources/store.go b/internal/unifiedresources/store.goindex 074ab68832..ba6860a108 100644--- a/internal/unifiedresources/store.go+++ b/internal/unifiedresources/store.go@@ -26,6 +26,7 @@ type ResourceStore interface {GetExclusions() ([]ResourceExclusion, error)RecordChange(change ResourceChange) errorGetRecentChanges(canonicalID string, since time.Time, limit int) ([]ResourceChange, error)+ CountRecentChanges(canonicalID string, since time.Time) (int, error)RecordActionAudit(record ActionAuditRecord) errorGetActionAudits(canonicalID string, since time.Time, limit int) ([]ActionAuditRecord, error)RecordActionLifecycleEvent(event ActionLifecycleEvent) error@@ -552,6 +553,25 @@ func (s *SQLiteResourceStore) GetRecentChanges(canonicalID string, since time.Tireturn changes, nil}+func (s *SQLiteResourceStore) CountRecentChanges(canonicalID string, since time.Time) (int, error) {+ query := `SELECT COUNT(*) FROM resource_changes WHERE observed_at >= ?`+ args := []any{since}+ canonicalID = CanonicalResourceID(canonicalID)+ if canonicalID != "" {+ query += ` AND canonical_id = ?`+ args = append(args, canonicalID)+ }++ s.mu.Lock()+ defer s.mu.Unlock()++ var count int+ if err := s.db.QueryRow(query, args...).Scan(&count); err != nil {+ return 0, fmt.Errorf("count resource changes: %w", err)+ }+ return count, nil+}+func (s *SQLiteResourceStore) RecordActionAudit(record ActionAuditRecord) error {s.mu.Lock()defer s.mu.Unlock()@@ -875,6 +895,23 @@ func (m *MemoryStore) GetRecentChanges(canonicalID string, since time.Time, limireturn out, nil}+func (m *MemoryStore) CountRecentChanges(canonicalID string, since time.Time) (int, error) {+ m.mu.RLock()+ defer m.mu.RUnlock()+ canonicalID = CanonicalResourceID(canonicalID)+ count := 0+ for _, change := range m.changes {+ if canonicalID != "" && CanonicalResourceID(change.ResourceID) != canonicalID {+ continue+ }+ if !since.IsZero() && change.ObservedAt.Before(since) {+ continue+ }+ count+++ }+ return count, nil+}+func (m *MemoryStore) RecordActionAudit(record ActionAuditRecord) error {m.mu.Lock()defer m.mu.Unlock()diff --git a/internal/unifiedresources/store_test.go b/internal/unifiedresources/store_test.goindex 3d98c70811..4faf1b1dbf 100644--- a/internal/unifiedresources/store_test.go+++ b/internal/unifiedresources/store_test.go@@ -270,6 +270,66 @@ func TestRecordChange_PreservesTimelineMetadata(t *testing.T) {}}+func TestCountRecentChanges_RespectsFilters(t *testing.T) {+ store := newTestStore(t)+ base := time.Date(2026, 3, 18, 12, 0, 0, 0, time.UTC)+ changes := []ResourceChange{+ {+ ID: "chg-count-1",+ ResourceID: "vm:1",+ ObservedAt: base.Add(-30 * time.Minute),+ Kind: ChangeStateTransition,+ SourceType: SourcePlatformEvent,+ Confidence: ConfidenceHigh,+ },+ {+ ID: "chg-count-2",+ ResourceID: "vm:1",+ ObservedAt: base.Add(-20 * time.Minute),+ Kind: ChangeAnomaly,+ SourceType: SourcePulseDiff,+ Confidence: ConfidenceMedium,+ },+ {+ ID: "chg-count-3",+ ResourceID: "vm:1",+ ObservedAt: base.Add(-10 * time.Minute),+ Kind: ChangeRelationship,+ SourceType: SourcePulseDiff,+ Confidence: ConfidenceLow,+ },+ {+ ID: "chg-count-4",+ ResourceID: "vm:2",+ ObservedAt: base.Add(-5 * time.Minute),+ Kind: ChangeCapability,+ SourceType: SourcePulseDiff,+ Confidence: ConfidenceLow,+ },+ }+ for _, change := range changes {+ if err := store.RecordChange(change); err != nil {+ t.Fatalf("RecordChange(%s): %v", change.ID, err)+ }+ }++ count, err := store.CountRecentChanges("vm:1", base.Add(-25*time.Minute))+ if err != nil {+ t.Fatalf("CountRecentChanges vm:1: %v", err)+ }+ if count != 2 {+ t.Fatalf("CountRecentChanges vm:1 = %d, want 2", count)+ }++ allCount, err := store.CountRecentChanges("", base.Add(-15*time.Minute))+ if err != nil {+ t.Fatalf("CountRecentChanges all: %v", err)+ }+ if allCount != 2 {+ t.Fatalf("CountRecentChanges all = %d, want 2", allCount)+ }+}+func TestActionAuditRecord_RoundTrip(t *testing.T) {store := newTestStore(t)now := time.Date(2026, 3, 18, 13, 0, 0, 0, time.UTC)