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.

Normalize pulse_query agent and storage floor

rcourtmand9d9dd958543
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index c0d8420251..14bafaa161 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -371,10 +371,13 @@ when policy redaction covers aliases, hostnames, or platform IDs instead of
persisting raw resource labels into cached AI facts.
That same `pulse_query` boundary now also owns canonical resource coverage for
API-backed platforms such as TrueNAS. The runtime must expose canonical
-`system`, `app-container`, `storage-pool`, and `physical-disk` views through
-the shared unified-resource model instead of falling back to Proxmox- or
-Docker-local enumerations when a platform projects onto canonical host,
-storage, disk, or workload contracts.
+`agent`, `app-container`, `storage`, and `physical-disk` resource views
+through the shared unified-resource model instead of falling back to Proxmox-
+or Docker-local enumerations when a platform projects onto canonical host,
+storage, disk, or workload contracts. Compatibility aliases such as
+`system` and `storage-pool` may still be accepted at the `pulse_query`
+boundary, but the governed runtime contract is the canonical `agent` /
+`storage` read path and the resolved-context registration emitted from it.
That same runtime contract applies to resource-native diagnostics. When
resolved context points at an API-backed canonical `app-container` such as a
TrueNAS app, chat/runtime prompt hints and tool execution must route log reads
diff --git a/internal/ai/tools/data_types.go b/internal/ai/tools/data_types.go
index ab8f6ed7a2..a8b515394f 100644
--- a/internal/ai/tools/data_types.go
+++ b/internal/ai/tools/data_types.go
@@ -238,7 +238,7 @@ func (r ResourceSearchResponse) NormalizeCollections() ResourceSearchResponse {
// ResourceMatch is a compact match result for pulse_search_resources
type ResourceMatch struct {
GovernedResourceMetadata
- Type string `json:"type"` // "node", "vm", "system-container", "app-container", "docker-host"
+ Type string `json:"type"` // "agent", "node", "vm", "system-container", "app-container", "docker-host", "storage"
ID string `json:"id,omitempty"`
Name string `json:"name"`
Status string `json:"status,omitempty"`
@@ -659,7 +659,7 @@ type TopologySummary struct {
// ResourceResponse is returned by pulse_get_resource
type ResourceResponse struct {
GovernedResourceMetadata
- Type string `json:"type"` // "vm", "system-container", "app-container"
+ Type string `json:"type"` // "agent", "vm", "system-container", "app-container", "storage"
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
diff --git a/internal/ai/tools/tools_query.go b/internal/ai/tools/tools_query.go
index a84fe18f4f..d7b2776d0a 100644
--- a/internal/ai/tools/tools_query.go
+++ b/internal/ai/tools/tools_query.go
@@ -2022,8 +2022,8 @@ func (e *PulseToolExecutor) registerQueryTools() {
},
"resource_type": {
Type: "string",
- Description: "Resource type. For get: 'system', 'vm', 'system-container', 'app-container'. For config: 'vm', 'system-container', or supported API-backed 'app-container'. For search: use type or resource_type with canonical values.",
- Enum: []string{"system", "vm", "system-container", "app-container", "node", "docker-host", "storage-pool", "physical-disk"},
+ Description: "Resource type. For get/search, prefer canonical values: 'agent', 'vm', 'system-container', 'app-container', 'storage', 'physical-disk', 'node', and 'docker-host'. Compatibility aliases 'system' and 'storage-pool' are still accepted. For config: 'vm', 'system-container', or supported API-backed 'app-container'.",
+ Enum: []string{"agent", "system", "vm", "system-container", "app-container", "node", "docker-host", "storage", "storage-pool", "physical-disk"},
},
"resource_id": {
Type: "string",
@@ -2031,8 +2031,8 @@ func (e *PulseToolExecutor) registerQueryTools() {
},
"type": {
Type: "string",
- Description: "Filter by type (for action: list/search): 'systems', 'nodes', 'vms', 'system-containers', 'app-containers', 'docker-hosts', 'storage-pools', 'physical-disks', 'kubernetes', 'k8s-clusters', 'k8s-nodes', 'k8s-pods', 'k8s-deployments'",
- Enum: []string{"systems", "nodes", "vms", "system-containers", "app-containers", "docker-hosts", "storage-pools", "physical-disks", "kubernetes", "k8s-clusters", "k8s-nodes", "k8s-pods", "k8s-deployments"},
+ Description: "Filter by type. For action=list, use plural families such as 'agents', 'systems', 'nodes', 'vms', 'system-containers', 'app-containers', 'docker-hosts', 'storages', 'storage-pools', and 'physical-disks'. For action=search, singular canonical kinds such as 'agent' and 'storage' are also accepted.",
+ Enum: []string{"agent", "agents", "systems", "nodes", "vms", "system-containers", "app-containers", "docker-hosts", "storage", "storages", "storage-pools", "physical-disks", "kubernetes", "k8s-clusters", "k8s-nodes", "k8s-pods", "k8s-deployments"},
},
"status": {
Type: "string",
@@ -2110,12 +2110,19 @@ func (e *PulseToolExecutor) registerQueryTools() {
}
func canonicalQueryResourceType(resourceType string) string {
- return strings.ToLower(strings.TrimSpace(resourceType))
+ switch strings.ToLower(strings.TrimSpace(resourceType)) {
+ case "system":
+ return "agent"
+ case "storage-pool":
+ return "storage"
+ default:
+ return strings.ToLower(strings.TrimSpace(resourceType))
+ }
}
func canonicalQueryListType(filterType string) string {
switch strings.ToLower(strings.TrimSpace(filterType)) {
- case "system":
+ case "system", "agent", "agents":
return "systems"
case "node":
return "nodes"
@@ -2127,7 +2134,7 @@ func canonicalQueryListType(filterType string) string {
return "app-containers"
case "docker-host":
return "docker-hosts"
- case "storage-pool":
+ case "storage", "storages", "storage-pool":
return "storage-pools"
case "physical-disk":
return "physical-disks"
@@ -2155,16 +2162,16 @@ func canonicalQueryTopologyInclude(include string) string {
func canonicalQuerySearchType(typeFilter string) string {
switch strings.ToLower(strings.TrimSpace(typeFilter)) {
- case "systems":
- return "system"
+ case "agent", "agents", "system", "systems":
+ return "agent"
case "system-containers":
return "system-container"
case "app-containers":
return "app-container"
case "docker-hosts":
return "docker-host"
- case "storage-pools":
- return "storage-pool"
+ case "storage", "storages", "storage-pool", "storage-pools":
+ return "storage"
case "physical-disks":
return "physical-disk"
case "docker-host":
@@ -2378,6 +2385,191 @@ func readOnlyResourceActions() []string {
return []string{"query", "get"}
}
+func commandCapableAgentActions(resource unifiedresources.Resource) []string {
+ if resource.Agent != nil && resource.Agent.CommandsEnabled {
+ return []string{"query", "get", "exec"}
+ }
+ return readOnlyResourceActions()
+}
+
+func canonicalResolvedProviderUID(kind string, resource unifiedresources.Resource, fallbacks ...string) string {
+ id := strings.TrimSpace(resource.ID)
+ prefix := strings.TrimSpace(kind) + ":"
+ if strings.HasPrefix(id, prefix) {
+ return strings.TrimSpace(strings.TrimPrefix(id, prefix))
+ }
+ for _, fallback := range fallbacks {
+ if fallback = strings.TrimSpace(fallback); fallback != "" {
+ return fallback
+ }
+ }
+ return id
+}
+
+func canonicalAgentHost(resource unifiedresources.Resource) string {
+ if resource.Agent != nil && strings.TrimSpace(resource.Agent.Hostname) != "" {
+ return strings.TrimSpace(resource.Agent.Hostname)
+ }
+ if resource.TrueNAS != nil && strings.TrimSpace(resource.TrueNAS.Hostname) != "" {
+ return strings.TrimSpace(resource.TrueNAS.Hostname)
+ }
+ for _, hostname := range resource.Identity.Hostnames {
+ if hostname = strings.TrimSpace(hostname); hostname != "" {
+ return hostname
+ }
+ }
+ return strings.TrimSpace(resource.Name)
+}
+
+func canonicalAgentManagedID(resource unifiedresources.Resource) string {
+ if resource.VMware != nil && strings.EqualFold(strings.TrimSpace(resource.VMware.EntityType), "host") {
+ connectionID := strings.TrimSpace(resource.VMware.ConnectionID)
+ managedObjectID := strings.TrimSpace(resource.VMware.ManagedObjectID)
+ if connectionID != "" && managedObjectID != "" {
+ return connectionID + ":host:" + managedObjectID
+ }
+ return managedObjectID
+ }
+ return ""
+}
+
+func canonicalAgentSearchCandidates(resource unifiedresources.Resource) []string {
+ candidates := []string{
+ resourceDisplayName(resource),
+ strings.TrimSpace(resource.ID),
+ canonicalAgentManagedID(resource),
+ canonicalResourcePlatform(resource),
+ }
+ candidates = append(candidates, resourceHostCandidates(resource)...)
+ if resource.Agent != nil {
+ candidates = append(candidates, strings.TrimSpace(resource.Agent.AgentID), strings.TrimSpace(resource.Agent.MachineID))
+ }
+ if resource.VMware != nil {
+ candidates = append(candidates, strings.TrimSpace(resource.VMware.ConnectionName), strings.TrimSpace(resource.VMware.HostUUID))
+ }
+ return appendUniqueStrings(nil, candidates...)
+}
+
+func canonicalAgentRegistration(resource unifiedresources.Resource) (ResourceRegistration, bool) {
+ name := strings.TrimSpace(resourceDisplayName(resource))
+ providerUID := canonicalResolvedProviderUID("agent", resource, canonicalAgentManagedID(resource), canonicalAgentHost(resource))
+ if name == "" || providerUID == "" {
+ return ResourceRegistration{}, false
+ }
+
+ executorID := firstNonEmptyString(canonicalAgentHost(resource), name, providerUID)
+ adapter := canonicalResourcePlatform(resource)
+ if resource.Agent != nil && resource.Agent.CommandsEnabled {
+ adapter = "direct"
+ }
+ return ResourceRegistration{
+ Kind: "agent",
+ ProviderUID: providerUID,
+ Name: name,
+ Aliases: canonicalAgentSearchCandidates(resource),
+ Executors: []ExecutorRegistration{{
+ ExecutorID: executorID,
+ Adapter: adapter,
+ Actions: commandCapableAgentActions(resource),
+ Priority: 10,
+ }},
+ }, true
+}
+
+func canonicalStorageManagedID(resource unifiedresources.Resource) string {
+ if resource.VMware != nil && strings.EqualFold(strings.TrimSpace(resource.VMware.EntityType), "datastore") {
+ connectionID := strings.TrimSpace(resource.VMware.ConnectionID)
+ managedObjectID := strings.TrimSpace(resource.VMware.ManagedObjectID)
+ if connectionID != "" && managedObjectID != "" {
+ return connectionID + ":datastore:" + managedObjectID
+ }
+ return managedObjectID
+ }
+ return ""
+}
+
+func canonicalStorageHost(resource unifiedresources.Resource) string {
+ if parent := strings.TrimSpace(resource.ParentName); parent != "" {
+ return parent
+ }
+ if resource.Storage != nil && len(resource.Storage.Nodes) == 1 {
+ if node := strings.TrimSpace(resource.Storage.Nodes[0]); node != "" {
+ return node
+ }
+ }
+ return ""
+}
+
+func canonicalStorageSearchCandidates(resource unifiedresources.Resource) []string {
+ candidates := []string{
+ resourceDisplayName(resource),
+ strings.TrimSpace(resource.ID),
+ canonicalStorageManagedID(resource),
+ canonicalResourcePlatform(resource),
+ canonicalStorageHost(resource),
+ }
+ if resource.Storage != nil {
+ candidates = append(candidates, resource.Storage.Type, resource.Storage.Content, resource.Storage.Path)
+ candidates = append(candidates, resource.Storage.Nodes...)
+ }
+ if resource.VMware != nil {
+ candidates = append(candidates, strings.TrimSpace(resource.VMware.ConnectionName), strings.TrimSpace(resource.VMware.DatacenterName))
+ }
+ candidates = append(candidates, resource.Tags...)
+ return appendUniqueStrings(nil, candidates...)
+}
+
+func canonicalStorageRegistration(resource unifiedresources.Resource) (ResourceRegistration, bool) {
+ name := strings.TrimSpace(resourceDisplayName(resource))
+ providerUID := canonicalResolvedProviderUID("storage", resource, canonicalStorageManagedID(resource), name)
+ if name == "" || providerUID == "" {
+ return ResourceRegistration{}, false
+ }
+
+ executorID := firstNonEmptyString(canonicalStorageHost(resource), name, providerUID)
+ return ResourceRegistration{
+ Kind: "storage",
+ ProviderUID: providerUID,
+ Name: name,
+ Aliases: canonicalStorageSearchCandidates(resource),
+ Executors: []ExecutorRegistration{{
+ ExecutorID: executorID,
+ Adapter: canonicalResourcePlatform(resource),
+ Actions: readOnlyResourceActions(),
+ Priority: 10,
+ }},
+ }, true
+}
+
+func findCanonicalResourceByID(resources []unifiedresources.Resource, resourceID string) (unifiedresources.Resource, bool) {
+ resourceID = strings.TrimSpace(resourceID)
+ if resourceID == "" {
+ return unifiedresources.Resource{}, false
+ }
+ for _, resource := range resources {
+ if strings.EqualFold(strings.TrimSpace(resource.ID), resourceID) {
+ return resource, true
+ }
+ }
+ return unifiedresources.Resource{}, false
+}
+
+func matchesCanonicalResourceReference(resource unifiedresources.Resource, resourceID string, additionalCandidates ...string) bool {
+ if matchesCanonicalResourceID(resource, resourceID) {
+ return true
+ }
+ resourceID = strings.TrimSpace(resourceID)
+ if resourceID == "" {
+ return false
+ }
+ for _, candidate := range additionalCandidates {
+ if strings.EqualFold(strings.TrimSpace(candidate), resourceID) {
+ return true
+ }
+ }
+ return false
+}
+
func canonicalGuestResourceType(kind string) (unifiedresources.ResourceType, bool) {
switch strings.TrimSpace(kind) {
case "vm":
@@ -2586,6 +2778,69 @@ func canonicalGuestResponse(kind string, resource unifiedresources.Resource, gov
return response.NormalizeCollections()
}
+func canonicalAgentResponse(resource unifiedresources.Resource, governance *governedQueryMetadataResolver) ResourceResponse {
+ candidates := canonicalAgentSearchCandidates(resource)
+ response := EmptyResourceResponse()
+ response.GovernedResourceMetadata = governance.Resolve(candidates...)
+ response.Type = "agent"
+ response.ID = strings.TrimSpace(resource.ID)
+ response.Name = resourceDisplayName(resource)
+ response.Status = string(resource.Status)
+ response.Platform = canonicalResourcePlatform(resource)
+ response.Host = canonicalAgentHost(resource)
+ response.CPU = ResourceCPU{
+ Percent: metricPercent(resourceMetric(resource, "cpu")),
+ }
+ response.Memory = ResourceMemory{
+ Percent: metricPercent(resourceMetric(resource, "memory")),
+ UsedGB: metricUsedGB(resourceMetric(resource, "memory")),
+ TotalGB: metricTotalGB(resourceMetric(resource, "memory")),
+ }
+ if diskMetric := resourceMetric(resource, "disk"); diskMetric != nil {
+ response.Disk = &ResourceDisk{
+ Percent: metricPercent(diskMetric),
+ UsedGB: metricUsedGB(diskMetric),
+ TotalGB: metricTotalGB(diskMetric),
+ }
+ }
+ response.Tags = append([]string{}, resource.Tags...)
+ if resource.Agent != nil {
+ response.OS = strings.TrimSpace(resource.Agent.OSName)
+ response.CPU.Cores = resource.Agent.CPUCount
+ }
+ if response.Host == "" && resource.TrueNAS != nil {
+ response.Host = strings.TrimSpace(resource.TrueNAS.Hostname)
+ }
+ if response.Host == "" {
+ response.Host = canonicalAgentHost(resource)
+ }
+ return response.NormalizeCollections()
+}
+
+func canonicalStorageResponse(resource unifiedresources.Resource, governance *governedQueryMetadataResolver) ResourceResponse {
+ candidates := canonicalStorageSearchCandidates(resource)
+ response := EmptyResourceResponse()
+ response.GovernedResourceMetadata = governance.Resolve(candidates...)
+ response.Type = "storage"
+ response.ID = strings.TrimSpace(resource.ID)
+ response.Name = resourceDisplayName(resource)
+ response.Status = string(resource.Status)
+ response.Platform = canonicalResourcePlatform(resource)
+ response.Host = canonicalStorageHost(resource)
+ if response.Host != "" {
+ response.Node = response.Host
+ }
+ if diskMetric := resourceMetric(resource, "disk"); diskMetric != nil {
+ response.Disk = &ResourceDisk{
+ Percent: metricPercent(diskMetric),
+ UsedGB: metricUsedGB(diskMetric),
+ TotalGB: metricTotalGB(diskMetric),
+ }
+ }
+ response.Tags = append([]string{}, resource.Tags...)
+ return response.NormalizeCollections()
+}
+
func canonicalAppContainerAdapter(resource unifiedresources.Resource) string {
switch canonicalResourcePlatform(resource) {
case "docker":
@@ -3953,50 +4208,42 @@ func (e *PulseToolExecutor) executeGetResource(_ context.Context, args map[strin
governance := newGovernedQueryMetadataResolver(rs)
switch resourceType {
- case "system":
+ case "agent":
if e.unifiedResourceProvider != nil {
for _, resource := range e.unifiedResourceProvider.GetByType(unifiedresources.ResourceTypeAgent) {
- if !matchesCanonicalResourceID(resource, resourceID) {
+ if !matchesCanonicalResourceReference(resource, resourceID, canonicalAgentSearchCandidates(resource)...) {
continue
}
- response := EmptyResourceResponse()
- response.GovernedResourceMetadata = governance.Resolve(resourceDisplayName(resource), resource.ID)
- response.Type = "system"
- response.ID = strings.TrimSpace(resource.ID)
- response.Name = resourceDisplayName(resource)
- response.Status = string(resource.Status)
- response.Platform = canonicalResourcePlatform(resource)
- response.CPU = ResourceCPU{
- Percent: metricPercent(resourceMetric(resource, "cpu")),
+ response := canonicalAgentResponse(resource, governance)
+ if reg, ok := canonicalAgentRegistration(resource); ok {
+ e.registerResolvedResourceWithExplicitAccess(reg)
}
- response.Memory = ResourceMemory{
- Percent: metricPercent(resourceMetric(resource, "memory")),
- UsedGB: metricUsedGB(resourceMetric(resource, "memory")),
- TotalGB: metricTotalGB(resourceMetric(resource, "memory")),
- }
- if diskMetric := resourceMetric(resource, "disk"); diskMetric != nil {
- response.Disk = &ResourceDisk{
- Percent: metricPercent(diskMetric),
- UsedGB: metricUsedGB(diskMetric),
- TotalGB: metricTotalGB(diskMetric),
- }
- }
- response.Tags = append([]string{}, resource.Tags...)
- if resource.Agent != nil {
- response.OS = strings.TrimSpace(resource.Agent.OSName)
- response.Host = strings.TrimSpace(resource.Agent.Hostname)
- response.CPU.Cores = resource.Agent.CPUCount
+ return NewJSONResult(response), nil
+ }
+ }
+ return NewJSONResult(map[string]interface{}{
+ "error": "not_found",
+ "resource_id": resourceID,
+ "type": "agent",
+ }), nil
+
+ case "storage":
+ if e.unifiedResourceProvider != nil {
+ for _, resource := range canonicalStoragePoolResources(e.unifiedResourceProvider) {
+ if !matchesCanonicalResourceReference(resource, resourceID, canonicalStorageSearchCandidates(resource)...) {
+ continue
}
- if response.Host == "" && resource.TrueNAS != nil {
- response.Host = strings.TrimSpace(resource.TrueNAS.Hostname)
+ response := canonicalStorageResponse(resource, governance)
+ if reg, ok := canonicalStorageRegistration(resource); ok {
+ e.registerResolvedResourceWithExplicitAccess(reg)
}
- return NewJSONResult(response.NormalizeCollections()), nil
+ return NewJSONResult(response), nil
}
}
return NewJSONResult(map[string]interface{}{
"error": "not_found",
"resource_id": resourceID,
- "type": "system",
+ "type": "storage",
}), nil
case "vm":
@@ -4338,7 +4585,7 @@ func (e *PulseToolExecutor) executeGetResource(_ context.Context, args map[strin
}), nil
default:
- return NewErrorResult(fmt.Errorf("invalid resource_type: %s. Use 'system', 'vm', 'system-container', or 'app-container'", resourceTypeRaw)), nil
+ return NewErrorResult(fmt.Errorf("invalid resource_type: %s. Use 'agent', 'vm', 'system-container', 'app-container', or 'storage' (compatibility aliases 'system' and 'storage-pool' are also accepted)", resourceTypeRaw)), nil
}
}
@@ -4714,17 +4961,17 @@ func (e *PulseToolExecutor) executeSearchResources(_ context.Context, args map[s
allowedTypes := map[string]bool{
"": true,
- "system": true,
+ "agent": true,
"node": true,
"vm": true,
"system-container": true,
"app-container": true,
"docker-host": true,
- "storage-pool": true,
+ "storage": true,
"physical-disk": true,
}
if !allowedTypes[typeFilter] {
- return NewErrorResult(fmt.Errorf("invalid type: %s. Use system, node, vm, system-container, app-container, docker-host, storage-pool, or physical-disk", typeFilter)), nil
+ return NewErrorResult(fmt.Errorf("invalid type: %s. Use agent, node, vm, system-container, app-container, docker-host, storage, or physical-disk (compatibility aliases system and storage-pool are also accepted)", typeFilter)), nil
}
// normalizeForSearch replaces common separators with spaces and splits at
@@ -4838,22 +5085,23 @@ func (e *PulseToolExecutor) executeSearchResources(_ context.Context, args map[s
total++
}
- if typeFilter == "" || typeFilter == "system" {
+ if typeFilter == "" || typeFilter == "agent" {
for _, resource := range systemResources {
status := string(resource.Status)
if !statusMatchesFilter(status, statusFilter) {
continue
}
- candidates := append(resourceHostCandidates(resource), resource.ID, canonicalResourcePlatform(resource))
+ candidates := canonicalAgentSearchCandidates(resource)
if !matchesQuery(queryLower, candidates...) {
continue
}
addMatch(ResourceMatch{
- GovernedResourceMetadata: governance.Resolve(resourceDisplayName(resource), resource.ID),
- Type: "system",
+ GovernedResourceMetadata: governance.Resolve(candidates...),
+ Type: "agent",
ID: resource.ID,
Name: resourceDisplayName(resource),
Status: status,
+ Host: canonicalAgentHost(resource),
Platform: canonicalResourcePlatform(resource),
AgentConnected: resourceAgentConnected(resource, connectedAgentHostnames),
})
@@ -5131,31 +5379,23 @@ func (e *PulseToolExecutor) executeSearchResources(_ context.Context, args map[s
}
}
- if typeFilter == "" || typeFilter == "storage-pool" {
+ if typeFilter == "" || typeFilter == "storage" {
for _, resource := range storagePoolResources {
status := string(resource.Status)
if !statusMatchesFilter(status, statusFilter) {
continue
}
- candidates := []string{
- resourceDisplayName(resource),
- resource.ID,
- canonicalResourcePlatform(resource),
- }
- if resource.Storage != nil {
- candidates = append(candidates, resource.Storage.Type, resource.Storage.Content, resource.Storage.Path)
- }
- candidates = append(candidates, resource.Tags...)
+ candidates := canonicalStorageSearchCandidates(resource)
if !matchesQuery(queryLower, candidates...) {
continue
}
addMatch(ResourceMatch{
- GovernedResourceMetadata: governance.Resolve(resourceDisplayName(resource), resource.ID),
- Type: "storage-pool",
+ GovernedResourceMetadata: governance.Resolve(candidates...),
+ Type: "storage",
ID: resource.ID,
Name: resourceDisplayName(resource),
Status: status,
- Host: strings.TrimSpace(resource.ParentName),
+ Host: canonicalStorageHost(resource),
Platform: canonicalResourcePlatform(resource),
})
}
@@ -5215,14 +5455,22 @@ func (e *PulseToolExecutor) executeSearchResources(_ context.Context, args map[s
var reg ResourceRegistration
switch match.Type {
- case "system":
- reg = ResourceRegistration{
- Kind: "system",
- ProviderUID: match.ID,
- Name: match.Name,
- Aliases: []string{match.Name, match.ID},
- HostUID: match.ID,
- HostName: match.Name,
+ case "agent":
+ if resource, ok := findCanonicalResourceByID(systemResources, match.ID); ok {
+ reg, _ = canonicalAgentRegistration(resource)
+ } else {
+ reg = ResourceRegistration{
+ Kind: "agent",
+ ProviderUID: strings.TrimPrefix(match.ID, "agent:"),
+ Name: match.Name,
+ Aliases: []string{match.Name, match.ID, match.Host},
+ Executors: []ExecutorRegistration{{
+ ExecutorID: firstNonEmptyString(match.Host, match.Name, match.ID),
+ Adapter: match.Platform,
+ Actions: readOnlyResourceActions(),
+ Priority: 10,
+ }},
+ }
}
case "node":
reg = ResourceRegistration{
@@ -5329,14 +5577,22 @@ func (e *PulseToolExecutor) executeSearchResources(_ context.Context, args map[s
Priority: 10,
}}
}
- case "storage-pool":
- reg = ResourceRegistration{
- Kind: "storage-pool",
- ProviderUID: match.ID,
- Name: match.Name,
- Aliases: []string{match.Name, match.ID},
- HostUID: match.Host,
- HostName: match.Host,
+ case "storage":
+ if resource, ok := findCanonicalResourceByID(storagePoolResources, match.ID); ok {
+ reg, _ = canonicalStorageRegistration(resource)
+ } else {
+ reg = ResourceRegistration{
+ Kind: "storage",
+ ProviderUID: strings.TrimPrefix(match.ID, "storage:"),
+ Name: match.Name,
+ Aliases: []string{match.Name, match.ID},
+ Executors: []ExecutorRegistration{{
+ ExecutorID: firstNonEmptyString(match.Host, match.Name, match.ID),
+ Adapter: match.Platform,
+ Actions: readOnlyResourceActions(),
+ Priority: 10,
+ }},
+ }
}
case "physical-disk":
reg = ResourceRegistration{
diff --git a/internal/ai/tools/tools_query_test.go b/internal/ai/tools/tools_query_test.go
index 91bed87d8c..7b12873a3c 100644
--- a/internal/ai/tools/tools_query_test.go
+++ b/internal/ai/tools/tools_query_test.go
@@ -264,6 +264,9 @@ func newVMwareUnifiedQueryProvider(t *testing.T) *registryUnifiedQueryProvider {
t.Helper()
now := time.Now().UTC()
+ diskUsed := int64(512 * 1024 * 1024 * 1024)
+ diskTotal := int64(1024 * 1024 * 1024 * 1024)
+ datastoreAccessible := true
registry := unifiedresources.NewRegistry(nil)
registry.IngestRecords(unifiedresources.SourceVMware, []unifiedresources.IngestRecord{
{
@@ -310,10 +313,65 @@ func newVMwareUnifiedQueryProvider(t *testing.T) *registryUnifiedQueryProvider {
IPAddresses: []string{"192.0.2.50"},
},
},
+ {
+ SourceID: "vc-1:datastore:datastore-11",
+ Resource: unifiedresources.Resource{
+ Type: unifiedresources.ResourceTypeStorage,
+ Name: "nvme-primary",
+ Status: unifiedresources.StatusOnline,
+ LastSeen: now,
+ UpdatedAt: now,
+ Metrics: &unifiedresources.ResourceMetrics{
+ Disk: &unifiedresources.MetricValue{
+ Used: &diskUsed,
+ Total: &diskTotal,
+ Percent: 50,
+ },
+ },
+ Storage: &unifiedresources.StorageMeta{
+ Type: "vmfs",
+ Platform: "vmware-vsphere",
+ Topology: "datastore",
+ Enabled: true,
+ Active: true,
+ Shared: false,
+ Nodes: []string{"esxi-01.lab.local"},
+ },
+ VMware: &unifiedresources.VMwareData{
+ ConnectionID: "vc-1",
+ ConnectionName: "Lab VC",
+ ManagedObjectID: "datastore-11",
+ EntityType: "datastore",
+ DatastoreAccessible: &datastoreAccessible,
+ },
+ },
+ },
})
return &registryUnifiedQueryProvider{ResourceRegistry: registry}
}
+func newCommandCapableAgentQueryProvider() *registryUnifiedQueryProvider {
+ now := time.Now().UTC()
+ registry := unifiedresources.NewRegistry(nil)
+ registry.IngestResources([]unifiedresources.Resource{{
+ ID: "agent:lab-host",
+ Type: unifiedresources.ResourceTypeAgent,
+ Name: "lab-host",
+ Status: unifiedresources.StatusOnline,
+ LastSeen: now,
+ UpdatedAt: now,
+ Agent: &unifiedresources.AgentData{
+ Hostname: "lab-host",
+ Platform: "linux",
+ CommandsEnabled: true,
+ },
+ Identity: unifiedresources.ResourceIdentity{
+ Hostnames: []string{"lab-host"},
+ },
+ }})
+ return &registryUnifiedQueryProvider{ResourceRegistry: registry}
+}
+
func TestCanonicalQueryListType_StrictV6Tokens(t *testing.T) {
if got := canonicalQueryListType("k8s-pods"); got != "k8s-pods" {
t.Fatalf("canonicalQueryListType(k8s-pods) = %q, want k8s-pods", got)
@@ -327,6 +385,15 @@ func TestCanonicalQueryListType_StrictV6Tokens(t *testing.T) {
if got := canonicalQueryListType("system"); got != "systems" {
t.Fatalf("canonicalQueryListType(system) = %q, want systems", got)
}
+ if got := canonicalQueryListType("agent"); got != "systems" {
+ t.Fatalf("canonicalQueryListType(agent) = %q, want systems", got)
+ }
+ if got := canonicalQueryListType("agents"); got != "systems" {
+ t.Fatalf("canonicalQueryListType(agents) = %q, want systems", got)
+ }
+ if got := canonicalQueryListType("storage"); got != "storage-pools" {
+ t.Fatalf("canonicalQueryListType(storage) = %q, want storage-pools", got)
+ }
if got := canonicalQueryListType("storage-pool"); got != "storage-pools" {
t.Fatalf("canonicalQueryListType(storage-pool) = %q, want storage-pools", got)
}
@@ -348,24 +415,39 @@ func TestCanonicalQueryTopologyInclude_StrictV6Tokens(t *testing.T) {
}
func TestCanonicalQuerySearchType_StrictV6Tokens(t *testing.T) {
+ if got := canonicalQuerySearchType("agent"); got != "agent" {
+ t.Fatalf("canonicalQuerySearchType(agent) = %q, want agent", got)
+ }
if got := canonicalQuerySearchType("docker-host"); got != "docker-host" {
t.Fatalf("canonicalQuerySearchType(docker-host) = %q, want docker-host", got)
}
if got := canonicalQuerySearchType("docker_host"); got != "docker_host" {
t.Fatalf("canonicalQuerySearchType(docker_host) = %q, want docker_host", got)
}
- if got := canonicalQuerySearchType("systems"); got != "system" {
- t.Fatalf("canonicalQuerySearchType(systems) = %q, want system", got)
+ if got := canonicalQuerySearchType("systems"); got != "agent" {
+ t.Fatalf("canonicalQuerySearchType(systems) = %q, want agent", got)
}
- if got := canonicalQuerySearchType("storage-pools"); got != "storage-pool" {
- t.Fatalf("canonicalQuerySearchType(storage-pools) = %q, want storage-pool", got)
+ if got := canonicalQuerySearchType("system"); got != "agent" {
+ t.Fatalf("canonicalQuerySearchType(system) = %q, want agent", got)
+ }
+ if got := canonicalQuerySearchType("storage"); got != "storage" {
+ t.Fatalf("canonicalQuerySearchType(storage) = %q, want storage", got)
+ }
+ if got := canonicalQuerySearchType("storage-pools"); got != "storage" {
+ t.Fatalf("canonicalQuerySearchType(storage-pools) = %q, want storage", got)
}
if got := canonicalQuerySearchType("physical-disks"); got != "physical-disk" {
t.Fatalf("canonicalQuerySearchType(physical-disks) = %q, want physical-disk", got)
}
}
-func TestCanonicalQueryHelpers_DoNotTranslateLegacyAliases(t *testing.T) {
+func TestCanonicalQueryHelpers_NormalizeCanonicalAgentAndStorageAliases(t *testing.T) {
+ if got := canonicalQueryResourceType("system"); got != "agent" {
+ t.Fatalf("canonicalQueryResourceType(system) = %q, want agent", got)
+ }
+ if got := canonicalQueryResourceType("storage-pool"); got != "storage" {
+ t.Fatalf("canonicalQueryResourceType(storage-pool) = %q, want storage", got)
+ }
if got := canonicalQueryResourceType("container"); got != "container" {
t.Fatalf("canonicalQueryResourceType(container) = %q, want container", got)
}
@@ -898,17 +980,17 @@ func TestExecuteQuery_UsesCanonicalTrueNASUnifiedResources(t *testing.T) {
searchPool, err := executor.executeSearchResources(context.Background(), map[string]interface{}{
"query": "archive",
- "type": "storage-pool",
+ "type": "storage",
})
if err != nil {
t.Fatalf("search storage pools: unexpected error: %v", err)
}
var searchResp ResourceSearchResponse
if err := json.Unmarshal([]byte(searchPool.Content[0].Text), &searchResp); err != nil {
- t.Fatalf("decode storage-pool search response: %v", err)
+ t.Fatalf("decode storage search response: %v", err)
}
- if len(searchResp.Matches) != 1 || searchResp.Matches[0].Type != "storage-pool" || searchResp.Matches[0].Name != "archive" || searchResp.Matches[0].Platform != "truenas" {
- t.Fatalf("unexpected storage-pool search response: %+v", searchResp.Matches)
+ if len(searchResp.Matches) != 1 || searchResp.Matches[0].Type != "storage" || searchResp.Matches[0].Name != "archive" || searchResp.Matches[0].Platform != "truenas" {
+ t.Fatalf("unexpected storage search response: %+v", searchResp.Matches)
}
searchDisk, err := executor.executeSearchResources(context.Background(), map[string]interface{}{
@@ -927,18 +1009,18 @@ func TestExecuteQuery_UsesCanonicalTrueNASUnifiedResources(t *testing.T) {
}
getSystem, err := executor.executeGetResource(context.Background(), map[string]interface{}{
- "resource_type": "system",
+ "resource_type": "agent",
"resource_id": "truenas-main",
})
if err != nil {
- t.Fatalf("get system: unexpected error: %v", err)
+ t.Fatalf("get agent: unexpected error: %v", err)
}
var systemRes ResourceResponse
if err := json.Unmarshal([]byte(getSystem.Content[0].Text), &systemRes); err != nil {
- t.Fatalf("decode system resource: %v", err)
+ t.Fatalf("decode agent resource: %v", err)
}
- if systemRes.Type != "system" || systemRes.Platform != "truenas" || systemRes.Host != "truenas-main" {
- t.Fatalf("unexpected canonical system resource: %+v", systemRes)
+ if systemRes.Type != "agent" || systemRes.Platform != "truenas" || systemRes.Host != "truenas-main" {
+ t.Fatalf("unexpected canonical agent resource: %+v", systemRes)
}
getApp, err := executor.executeGetResource(context.Background(), map[string]interface{}{
@@ -1052,6 +1134,117 @@ func TestExecuteGetResource_RegistersVMwareVMAsReadOnly(t *testing.T) {
}
}
+func TestExecuteGetResource_RegistersVMwareAgentAsReadOnly(t *testing.T) {
+ provider := newVMwareUnifiedQueryProvider(t)
+ hostResources := provider.GetByType(unifiedresources.ResourceTypeAgent)
+ if len(hostResources) != 1 {
+ t.Fatalf("expected one VMware host resource, got %d", len(hostResources))
+ }
+
+ resolved := &mockResolvedContext{
+ resources: make(map[string]ResolvedResourceInfo),
+ aliases: make(map[string]ResolvedResourceInfo),
+ }
+ executor := NewPulseToolExecutor(ExecutorConfig{
+ UnifiedResourceProvider: provider,
+ ReadState: provider.ResourceRegistry,
+ })
+ executor.SetResolvedContext(resolved)
+
+ result, err := executor.executeGetResource(context.Background(), map[string]interface{}{
+ "resource_type": "agent",
+ "resource_id": hostResources[0].ID,
+ })
+ if err != nil {
+ t.Fatalf("get agent: unexpected error: %v", err)
+ }
+
+ var response ResourceResponse
+ if err := json.Unmarshal([]byte(result.Content[0].Text), &response); err != nil {
+ t.Fatalf("decode response: %v", err)
+ }
+ if response.Type != "agent" || response.Platform != "vmware-vsphere" || response.Host != "esxi-01.lab.local" {
+ t.Fatalf("unexpected VMware agent response: %+v", response)
+ }
+
+ info, found := resolved.GetResolvedResourceByAlias("esxi-01.lab.local")
+ if !found {
+ t.Fatal("expected resolved context to include VMware host by alias")
+ }
+ if info.GetKind() != "agent" {
+ t.Fatalf("expected agent kind, got %q", info.GetKind())
+ }
+ if info.GetAdapter() != "vmware-vsphere" {
+ t.Fatalf("expected VMware adapter, got %q", info.GetAdapter())
+ }
+ if got := strings.Join(info.GetAllowedActions(), ","); got != "query,get" && got != "get,query" {
+ t.Fatalf("expected VMware host to register read-only actions, got %v", info.GetAllowedActions())
+ }
+
+ controlResult, err := executor.executeControl(context.Background(), map[string]interface{}{
+ "type": "resource",
+ "resource_id": "esxi-01.lab.local",
+ "action": "restart",
+ })
+ if err != nil {
+ t.Fatalf("executeControl(type=resource): unexpected error: %v", err)
+ }
+ if !controlResult.IsError {
+ t.Fatalf("expected VMware host restart to be rejected, got %+v", controlResult)
+ }
+ if !strings.Contains(controlResult.Content[0].Text, "not permitted") {
+ t.Fatalf("expected read-only rejection, got %q", controlResult.Content[0].Text)
+ }
+}
+
+func TestExecuteGetResource_RegistersVMwareStorageAsReadOnly(t *testing.T) {
+ provider := newVMwareUnifiedQueryProvider(t)
+ storageResources := provider.GetByType(unifiedresources.ResourceTypeStorage)
+ if len(storageResources) != 1 {
+ t.Fatalf("expected one VMware storage resource, got %d", len(storageResources))
+ }
+
+ resolved := &mockResolvedContext{
+ resources: make(map[string]ResolvedResourceInfo),
+ aliases: make(map[string]ResolvedResourceInfo),
+ }
+ executor := NewPulseToolExecutor(ExecutorConfig{
+ UnifiedResourceProvider: provider,
+ ReadState: provider.ResourceRegistry,
+ })
+ executor.SetResolvedContext(resolved)
+
+ result, err := executor.executeGetResource(context.Background(), map[string]interface{}{
+ "resource_type": "storage",
+ "resource_id": storageResources[0].ID,
+ })
+ if err != nil {
+ t.Fatalf("get storage: unexpected error: %v", err)
+ }
+
+ var response ResourceResponse
+ if err := json.Unmarshal([]byte(result.Content[0].Text), &response); err != nil {
+ t.Fatalf("decode response: %v", err)
+ }
+ if response.Type != "storage" || response.Platform != "vmware-vsphere" || response.Name != "nvme-primary" {
+ t.Fatalf("unexpected VMware storage response: %+v", response)
+ }
+ if response.Disk == nil || response.Disk.TotalGB == 0 {
+ t.Fatalf("expected VMware storage capacity details, got %+v", response)
+ }
+
+ info, found := resolved.GetResolvedResourceByAlias("nvme-primary")
+ if !found {
+ t.Fatal("expected resolved context to include VMware storage by alias")
+ }
+ if info.GetKind() != "storage" {
+ t.Fatalf("expected storage kind, got %q", info.GetKind())
+ }
+ if got := strings.Join(info.GetAllowedActions(), ","); got != "query,get" && got != "get,query" {
+ t.Fatalf("expected VMware storage to register read-only actions, got %v", info.GetAllowedActions())
+ }
+}
+
func TestExecuteSearchResources_RegistersVMwareVMAsReadOnly(t *testing.T) {
provider := newVMwareUnifiedQueryProvider(t)
resolved := &mockResolvedContext{
@@ -1092,6 +1285,118 @@ func TestExecuteSearchResources_RegistersVMwareVMAsReadOnly(t *testing.T) {
}
}
+func TestExecuteSearchResources_RegistersVMwareAgentAsReadOnly(t *testing.T) {
+ provider := newVMwareUnifiedQueryProvider(t)
+ resolved := &mockResolvedContext{
+ resources: make(map[string]ResolvedResourceInfo),
+ aliases: make(map[string]ResolvedResourceInfo),
+ }
+ executor := NewPulseToolExecutor(ExecutorConfig{
+ UnifiedResourceProvider: provider,
+ ReadState: provider.ResourceRegistry,
+ })
+ executor.SetResolvedContext(resolved)
+
+ result, err := executor.executeSearchResources(context.Background(), map[string]interface{}{
+ "query": "esxi-01",
+ "type": "agent",
+ })
+ if err != nil {
+ t.Fatalf("search agent: unexpected error: %v", err)
+ }
+
+ var response ResourceSearchResponse
+ if err := json.Unmarshal([]byte(result.Content[0].Text), &response); err != nil {
+ t.Fatalf("decode search response: %v", err)
+ }
+ if len(response.Matches) != 1 {
+ t.Fatalf("expected one VMware host search match, got %+v", response.Matches)
+ }
+ if response.Matches[0].Type != "agent" || response.Matches[0].Platform != "vmware-vsphere" {
+ t.Fatalf("unexpected VMware host search match: %+v", response.Matches[0])
+ }
+
+ info, found := resolved.GetResolvedResourceByAlias("esxi-01.lab.local")
+ if !found {
+ t.Fatal("expected VMware host search result to register in resolved context")
+ }
+ if got := strings.Join(info.GetAllowedActions(), ","); got != "query,get" && got != "get,query" {
+ t.Fatalf("expected VMware host search registration to remain read-only, got %v", info.GetAllowedActions())
+ }
+}
+
+func TestExecuteSearchResources_RegistersVMwareStorageAsReadOnly(t *testing.T) {
+ provider := newVMwareUnifiedQueryProvider(t)
+ resolved := &mockResolvedContext{
+ resources: make(map[string]ResolvedResourceInfo),
+ aliases: make(map[string]ResolvedResourceInfo),
+ }
+ executor := NewPulseToolExecutor(ExecutorConfig{
+ UnifiedResourceProvider: provider,
+ ReadState: provider.ResourceRegistry,
+ })
+ executor.SetResolvedContext(resolved)
+
+ result, err := executor.executeSearchResources(context.Background(), map[string]interface{}{
+ "query": "nvme-primary",
+ "type": "storage",
+ })
+ if err != nil {
+ t.Fatalf("search storage: unexpected error: %v", err)
+ }
+
+ var response ResourceSearchResponse
+ if err := json.Unmarshal([]byte(result.Content[0].Text), &response); err != nil {
+ t.Fatalf("decode search response: %v", err)
+ }
+ if len(response.Matches) != 1 {
+ t.Fatalf("expected one VMware storage search match, got %+v", response.Matches)
+ }
+ if response.Matches[0].Type != "storage" || response.Matches[0].Platform != "vmware-vsphere" {
+ t.Fatalf("unexpected VMware storage search match: %+v", response.Matches[0])
+ }
+
+ info, found := resolved.GetResolvedResourceByAlias("nvme-primary")
+ if !found {
+ t.Fatal("expected VMware storage search result to register in resolved context")
+ }
+ if got := strings.Join(info.GetAllowedActions(), ","); got != "query,get" && got != "get,query" {
+ t.Fatalf("expected VMware storage search registration to remain read-only, got %v", info.GetAllowedActions())
+ }
+}
+
+func TestExecuteGetResource_RegistersCommandCapableAgentForExec(t *testing.T) {
+ provider := newCommandCapableAgentQueryProvider()
+ resolved := &mockResolvedContext{
+ resources: make(map[string]ResolvedResourceInfo),
+ aliases: make(map[string]ResolvedResourceInfo),
+ }
+ executor := NewPulseToolExecutor(ExecutorConfig{
+ UnifiedResourceProvider: provider,
+ ReadState: provider.ResourceRegistry,
+ })
+ executor.SetResolvedContext(resolved)
+
+ _, err := executor.executeGetResource(context.Background(), map[string]interface{}{
+ "resource_type": "agent",
+ "resource_id": "lab-host",
+ })
+ if err != nil {
+ t.Fatalf("get agent: unexpected error: %v", err)
+ }
+
+ info, found := resolved.GetResolvedResourceByAlias("lab-host")
+ if !found {
+ t.Fatal("expected command-capable agent to register in resolved context")
+ }
+ allowed := strings.Join(info.GetAllowedActions(), ",")
+ for _, action := range []string{"query", "get", "exec"} {
+ if !strings.Contains(allowed, action) {
+ t.Fatalf("expected allowed actions to include %q, got %v", action, info.GetAllowedActions())
+ }
+ }
+}
+
func TestExecuteQuerySurfacesIncludeGovernedMetadata(t *testing.T) {
state := models.StateSnapshot{
Nodes: []models.Node{