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.

Carry per-fact discovery provenance through to the model

rcourtmana24e944f1b8e
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index d4518a343e..247bb26c27 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -1875,6 +1875,10 @@ deriving an older display status from `workflowStatusHistory`.
`ActionPlan.Preflight` dry-run boundary through
`internal/ai/tools/action_audit.go` rather than leaving dry-run availability
as chat-only text.
+ The `pulse_discovery` tool response must carry each discovered fact's
+ provenance — the `source` that produced it and its `confidence` — alongside
+ the fact's category/key/value, so the model can attribute and weight what it
+ reports instead of stating untraceable facts. Both are omitted when empty.
When the shared registry blocks a control tool in read-only mode, its
operator guidance must point to Assistant & Patrol settings and the Pulse
Assistant Permissions Control mode, not legacy Pulse Assistant settings
diff --git a/internal/ai/tools/tools_discovery.go b/internal/ai/tools/tools_discovery.go
index 1de4867a77..cd8a030b87 100644
--- a/internal/ai/tools/tools_discovery.go
+++ b/internal/ai/tools/tools_discovery.go
@@ -482,15 +482,25 @@ func buildDiscoveryToolResponse(req discoveryResourceRequest, discovery *Resourc
response["log_paths"] = responseLogPaths
}
- // Add facts if present
+ // Add facts if present. Carry each fact's provenance — the source that
+ // produced it and its confidence — so the model can attribute and weight
+ // what it reports ("Debian 12, per /etc/os-release") instead of stating
+ // bare facts the user cannot trace. Both are optional and omitted when empty.
if len(discovery.Facts) > 0 {
- facts := make([]map[string]string, 0, len(discovery.Facts))
+ facts := make([]map[string]interface{}, 0, len(discovery.Facts))
for _, f := range discovery.Facts {
- facts = append(facts, map[string]string{
+ fact := map[string]interface{}{
"category": f.Category,
"key": f.Key,
"value": f.Value,
- })
+ }
+ if f.Source != "" {
+ fact["source"] = f.Source
+ }
+ if f.Confidence > 0 {
+ fact["confidence"] = f.Confidence
+ }
+ facts = append(facts, fact)
}
response["facts"] = facts
}
diff --git a/internal/ai/tools/tools_discovery_test.go b/internal/ai/tools/tools_discovery_test.go
index 8d40d8f8df..7f0c538a52 100644
--- a/internal/ai/tools/tools_discovery_test.go
+++ b/internal/ai/tools/tools_discovery_test.go
@@ -450,6 +450,42 @@ func TestBuildDiscoveryToolResponse_OmitsOptionalMountFields(t *testing.T) {
}
}
+func TestBuildDiscoveryToolResponse_IncludesFactProvenance(t *testing.T) {
+ req := discoveryResourceRequest{
+ resourceType: "system-container",
+ resourceID: "101",
+ targetID: "node1",
+ }
+ discovery := &ResourceDiscoveryInfo{
+ ID: "system-container:node1:101",
+ ResourceType: "system-container",
+ ResourceID: "101",
+ TargetID: "node1",
+ Facts: []DiscoveryFact{
+ {Category: "version", Key: "os", Value: "Debian 12", Source: "/etc/os-release", Confidence: 0.95},
+ {Category: "service", Key: "unit", Value: "home-assistant.service"}, // no source/confidence
+ },
+ }
+
+ resp := buildDiscoveryToolResponse(req, discovery)
+
+ rawFacts, ok := resp["facts"].([]map[string]interface{})
+ if !ok {
+ t.Fatalf("expected facts to be []map[string]interface{}, got %T", resp["facts"])
+ }
+ if assert.Len(t, rawFacts, 2) {
+ // A fact with provenance carries source + confidence so the model can
+ // attribute and weight it.
+ assert.Equal(t, "Debian 12", rawFacts[0]["value"])
+ assert.Equal(t, "/etc/os-release", rawFacts[0]["source"])
+ assert.Equal(t, 0.95, rawFacts[0]["confidence"])
+ // A fact without provenance omits the optional fields cleanly.
+ assert.Equal(t, "home-assistant.service", rawFacts[1]["value"])
+ assert.NotContains(t, rawFacts[1], "source")
+ assert.NotContains(t, rawFacts[1], "confidence")
+ }
+}
+
func TestExecuteRunDiscovery_ForcesFreshDiscovery(t *testing.T) {
provider := &stubDiscoveryProvider{
triggerResp: &ResourceDiscoveryInfo{