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
Preserve explicit Assistant tool intent
rcourtman335c37b01a30
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 40e559774d..5869823273 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -742,6 +742,20 @@ runtime cost control, and shared AI transport surfaces.The completion metadata for that path should identify the effective routeas `pulse:local-inventory` so the transcript label reflects Pulse-ownedlocal runtime output instead of the operator's selected remote model.+ Explicit operator tool intent is the escape hatch from this shortcut, not a+ Pulse-authored tool choice: prompts that ask to use tools, request a+ read-only attempt, or provide a shell/read command or path such as+ `ls /dev | wc -l` must keep the full governed Assistant tool manifest and+ reach the selected model/provider instead of answering from local inventory.+ Pulse may classify that turn as full-manifest, but the selected model still+ decides whether to call `pulse_read`, answer directly, or ask a+ clarification. This adapts the referenced OpenCode source at fetched+ `origin/dev` commit `4519a1da329c1a4fc384054e7203ba7d06928205`, where+ `packages/core/src/session/message-updater.ts` mutates tool input, called,+ progress, success, and failed states as typed session events (lines+ 247-318), by preserving the operator's explicit tool intent until Pulse can+ stream a visible `tool_start` / `tool_progress` / `tool_end` path instead of+ collapsing the turn into unrelated inventory prose.The compact payload must include exact `answer_label` fields for nodes andworkloads; the provider-facing instruction must tell the model to copy thoselabels exactly instead of substituting generic labels like `Node 1`, `VMdiff --git a/internal/ai/chat/service.go b/internal/ai/chat/service.goindex 6207b83c63..534a8cc78b 100644--- a/internal/ai/chat/service.go+++ b/internal/ai/chat/service.go@@ -4358,7 +4358,7 @@ func assistantToolScopeForPrompt(prompt string, hasModelContext bool) assistantTif normalized == "" {return assistantTurnToolScopeTextOnly}- if assistantPromptRequestsDirectText(normalized) {+ if assistantPromptRequestsDirectText(normalized) || assistantPromptDisallowsToolUse(normalized) {return assistantTurnToolScopeTextOnly}if assistantPromptNeedsFullToolManifest(normalized) {@@ -4394,6 +4394,7 @@ func normalizeAssistantToolRoutingPrompt(prompt string) string {"]", " ","{", " ","}", " ",+ "`", " ","\"", " ","'", " ",)@@ -4417,7 +4418,26 @@ func assistantPromptRequestsDirectText(normalized string) bool {})}+func assistantPromptDisallowsToolUse(normalized string) bool {+ return assistantPromptContainsAny(normalized, []string{+ " no tools ",+ " without tools ",+ " without using tools ",+ " do not use tools ",+ " don't use tools ",+ " dont use tools ",+ " before using tools ",+ " before using any tools ",+ " before you use tools ",+ " before calling tools ",+ " before you call tools ",+ })+}+func assistantPromptNeedsFullToolManifest(normalized string) bool {+ if assistantPromptExplicitlyRequestsToolUse(normalized) || assistantPromptLooksLikeShellRead(normalized) {+ return true+ }return assistantPromptContainsAny(normalized, []string{" run "," execute ",@@ -4474,6 +4494,80 @@ func assistantPromptNeedsFullToolManifest(normalized string) bool {})}+func assistantPromptExplicitlyRequestsToolUse(normalized string) bool {+ return assistantPromptContainsAny(normalized, []string{+ " use tools ",+ " use a tool ",+ " use the tool ",+ " use read-only tools ",+ " use read only tools ",+ " using read-only tools ",+ " using read only tools ",+ " read-only tools only ",+ " read only tools only ",+ " one read-only tool ",+ " one read only tool ",+ " call a tool ",+ " call the tool ",+ " call pulse_read ",+ " pulse_read ",+ " pulse_control ",+ " pulse_query ",+ " read attempt ",+ " read-only attempt ",+ " read only attempt ",+ " fresh verification ",+ " live runtime state ",+ })+}++func assistantPromptLooksLikeShellRead(normalized string) bool {+ shellCommands := []string{+ " awk ",+ " cat ",+ " df ",+ " docker ",+ " du ",+ " find ",+ " grep ",+ " head ",+ " journalctl ",+ " kubectl ",+ " ls ",+ " pct ",+ " ps ",+ " qm ",+ " sed ",+ " smartctl ",+ " systemctl ",+ " tail ",+ " wc ",+ " zfs ",+ " zpool ",+ }+ if strings.Contains(normalized, " | ") && assistantPromptContainsAny(normalized, shellCommands) {+ return true+ }+ if assistantPromptContainsAny(normalized, []string{+ " /dev",+ " /etc/",+ " /proc",+ " /sys",+ " /var/log",+ }) && assistantPromptContainsAny(normalized, shellCommands) {+ return true+ }+ return assistantPromptContainsAny(normalized, []string{+ " docker logs ",+ " journalctl -",+ " kubectl logs ",+ " ls /",+ " pct exec ",+ " qm guest exec ",+ " systemctl status ",+ })+}+func assistantPromptIsInventoryQuery(normalized string) bool {hasInventoryNoun := assistantPromptContainsAny(normalized, []string{" device ",diff --git a/internal/ai/chat/service_execute_additional_test.go b/internal/ai/chat/service_execute_additional_test.goindex 7ca0067c06..04549b202e 100644--- a/internal/ai/chat/service_execute_additional_test.go+++ b/internal/ai/chat/service_execute_additional_test.go@@ -1201,9 +1201,19 @@ func TestService_ExecuteStream_InventoryCountAnswersFromCanonicalStateWithoutPro}var providerCalled atomic.Bool+ var capturedProviderTools []providers.Toolprovider := &stubServiceProvider{streamFn: func(ctx context.Context, req providers.ChatRequest, callback providers.StreamCallback) error {providerCalled.Store(true)+ capturedProviderTools = append([]providers.Tool(nil), req.Tools...)+ callback(providers.StreamEvent{+ Type: "content",+ Data: providers.ContentEvent{Text: "provider-backed count"},+ })+ callback(providers.StreamEvent{+ Type: "done",+ Data: providers.DoneEvent{InputTokens: 1, OutputTokens: 1},+ })return nil},}@@ -1356,6 +1366,63 @@ func TestService_ExecuteStream_InventoryCountAnswersFromCanonicalStateWithoutProif len(messages) != 2 || messages[1].Role != "assistant" || messages[1].Content != answer {t.Fatalf("expected direct assistant answer to be persisted, got %#v", messages)}++ providerCalled.Store(false)+ capturedProviderTools = nil+ content.Reset()+ doneSeen = false+ doneModel = ""+ countedProgressSeen = false+ err = service.ExecuteStream(context.Background(), ExecuteRequest{+ SessionID: "inventory-count-explicit-command",+ Prompt: "Use read-only tools only. On node delly, count entries in /dev with `ls /dev | wc -l`; answer with the number only.",+ }, func(event StreamEvent) {+ switch event.Type {+ case "content":+ var data ContentData+ if err := json.Unmarshal(event.Data, &data); err != nil {+ t.Fatalf("unmarshal explicit content: %v", err)+ }+ content.WriteString(data.Text)+ case "done":+ doneSeen = true+ var data DoneData+ if err := json.Unmarshal(event.Data, &data); err != nil {+ t.Fatalf("unmarshal explicit done: %v", err)+ }+ doneModel = data.Model+ case "workflow_state":+ var data WorkflowStateData+ if err := json.Unmarshal(event.Data, &data); err != nil {+ t.Fatalf("unmarshal explicit workflow state: %v", err)+ }+ if data.Phase == "context_ready" && data.Message == "Counted current Pulse inventory." {+ countedProgressSeen = true+ }+ }+ })+ if err != nil {+ t.Fatalf("explicit command ExecuteStream failed: %v", err)+ }+ if !providerCalled.Load() {+ t.Fatal("expected explicit command count to reach provider")+ }+ if !doneSeen {+ t.Fatal("explicit command turn did not emit done")+ }+ if doneModel == assistantLocalInventoryModelRoute {+ t.Fatalf("explicit command count used local inventory route %q", doneModel)+ }+ if countedProgressSeen {+ t.Fatal("explicit command count should not emit deterministic local inventory progress")+ }+ if got := content.String(); !strings.Contains(got, "provider-backed count") {+ t.Fatalf("expected provider-backed content, got %q", got)+ }+ set := toolNameSet(capturedProviderTools)+ if !set["pulse_read"] {+ t.Fatalf("expected explicit command count to expose pulse_read, got %#v", set)+ }}func TestService_ExecuteStream_PrefetchedInventoryIncludesCompleteTopologyDetail(t *testing.T) {diff --git a/internal/ai/chat/service_tooling_test.go b/internal/ai/chat/service_tooling_test.goindex 4e017aae81..f801cd4f6c 100644--- a/internal/ai/chat/service_tooling_test.go+++ b/internal/ai/chat/service_tooling_test.go@@ -179,6 +179,25 @@ func TestToolsForAssistantTurn_InventoryCountUsesQueryOnly(t *testing.T) {}}+func TestToolsForAssistantTurn_ExplicitCommandCountKeepsFullManifest(t *testing.T) {+ exec := tools.NewPulseToolExecutor(tools.ExecutorConfig{+ StateProvider: fakeStateProvider{},+ AgentServer: fakeAgentServer{},+ ReadState: &fakeCanonicalReadState{},+ ControlLevel: tools.ControlLevelControlled,+ })++ svc := &Service{executor: exec}+ toolsList := svc.toolsForAssistantTurn("Use read-only tools only. On node delly, count entries in /dev with `ls /dev | wc -l`; answer with the number only.", false, false, false)+ set := toolNameSet(toolsList)++ for _, required := range []string{"pulse_read", "pulse_query", pulseQuestionToolName} {+ if !set[required] {+ t.Fatalf("expected explicit command count prompt to expose %s, got %#v", required, set)+ }+ }+}+func TestToolsForAssistantTurn_InventoryBreakdownUsesQueryOnly(t *testing.T) {exec := tools.NewPulseToolExecutor(tools.ExecutorConfig{StateProvider: fakeStateProvider{},