perf(agent): read traffic capture setting once per findingWorkflowTools pass

This commit is contained in:
BaaRai
2026-11-21 17:01:15 +01:00
parent b56ad38b43
commit 1adfc21346
2 changed files with 13 additions and 5 deletions
+5 -4
View File
@@ -73,8 +73,8 @@ const (
trafficCaptureOffReportFindingNote = "\nNote: traffic capture is currently OFF on this server, so no HTTP traffic is being recorded. Findings still save with textual/command evidence, but cannot prove goals via prove_goal until traffic capture is enabled in System settings and verified traffic is bound."
)
func trafficCaptureOffToolNote(toolName string) string {
if !trafficCaptureExplicitlyOff() {
func trafficCaptureOffToolNote(toolName string, captureOff bool) string {
if !captureOff {
return ""
}
switch toolName {
@@ -91,6 +91,7 @@ func trafficCaptureOffToolNote(toolName string) string {
// all actual reporters (including Planner and custom chat agents) see the same
// API contract. Disabled/unbound tools are never reintroduced here.
func findingWorkflowTools(agentKey string, tools []actool.CoreTool) ([]actool.CoreTool, string) {
captureOff := trafficCaptureExplicitlyOff()
if !findingTrafficBindingEnabled() {
out := make([]actool.CoreTool, 0, len(tools))
for _, tool := range tools {
@@ -114,7 +115,7 @@ func findingWorkflowTools(agentKey string, tools []actool.CoreTool) ([]actool.Co
decorated = true
}
}
if note := trafficCaptureOffToolNote(tool.Name()); note != "" {
if note := trafficCaptureOffToolNote(tool.Name(), captureOff); note != "" {
desc += note
decorated = true
}
@@ -138,7 +139,7 @@ func findingWorkflowTools(agentKey string, tools []actool.CoreTool) ([]actool.Co
case "get_finding_traffic", "bind_finding_traffic", "list_findings", "list_task_findings", "node_detail", "get_task_node_detail", "update_finding_report":
note = findingIDGuidance
}
if capNote := trafficCaptureOffToolNote(tool.Name()); capNote != "" {
if capNote := trafficCaptureOffToolNote(tool.Name(), captureOff); capNote != "" {
note += capNote
}
if note != "" {
+8 -1
View File
@@ -87,9 +87,16 @@ func TestFindingWorkflowToolsTrafficCaptureOffNotice(t *testing.T) {
for _, binding := range []bool{false, true} {
SetFindingTrafficBindingEnabled(func() bool { return binding })
SetTrafficCaptureEnabled(func() bool { return false })
calls := 0
SetTrafficCaptureEnabled(func() bool {
calls++
return false
})
outOff, _, clOff := AugmentTools(t.Context(), "planner", base)
clOff()
if calls != 1 {
t.Fatalf("binding=%v: capture hook called %d times for %d tools, want 1", binding, calls, len(base))
}
for _, tool := range outOff {
desc := tool.Description()
switch tool.Name() {