From b56ad38b4348a1293a29d47436bf99c3a2b5ec12 Mon Sep 17 00:00:00 2001 From: BaaRai <130491490+BaaRai@users.noreply.github.com> Date: Sat, 21 Nov 2026 16:35:31 +0100 Subject: [PATCH] feat(agent,web): explain that traffic capture is off and required for provable findings --- agent/finding_workflow.go | 66 +++++++++++++++++++-- agent/finding_workflow_test.go | 44 ++++++++++++++ server/assembly.go | 1 + web/src/app/(auth)/setup/page.tsx | 3 + web/src/app/(main)/dashboard/page.tsx | 40 ++++++++----- web/src/app/(main)/system/settings/page.tsx | 27 +++++---- web/src/i18n/locales/tr.json | 6 +- web/src/i18n/locales/zh-CN.json | 6 +- 8 files changed, 163 insertions(+), 30 deletions(-) diff --git a/agent/finding_workflow.go b/agent/finding_workflow.go index de0f04f..0099cd2 100644 --- a/agent/finding_workflow.go +++ b/agent/finding_workflow.go @@ -43,6 +43,50 @@ func findingTrafficBindingEnabled() bool { return f != nil && f() } +var ( + trafficCaptureMu sync.RWMutex + trafficCaptureHook func() bool +) + +// SetTrafficCaptureEnabled installs (or, with nil, removes) the hook that +// reports whether the server's global traffic capture switch is currently on. +func SetTrafficCaptureEnabled(f func() bool) { + trafficCaptureMu.Lock() + trafficCaptureHook = f + trafficCaptureMu.Unlock() +} + +// TrafficCaptureEnabled returns the current hook, or nil when none is set. +func TrafficCaptureEnabled() func() bool { + trafficCaptureMu.RLock() + defer trafficCaptureMu.RUnlock() + return trafficCaptureHook +} + +func trafficCaptureExplicitlyOff() bool { + f := TrafficCaptureEnabled() + return f != nil && !f() +} + +const ( + trafficCaptureOffProveGoalNote = "\nNote: traffic capture is currently OFF on this server, so no HTTP traffic is being recorded and findings cannot be bound to captured traffic to prove HTTP goals. Recorded findings stay visible, and non-HTTP goals can still be proved with an observed tool_output fact; enable traffic capture in System settings to make HTTP findings provable." + 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() { + return "" + } + switch toolName { + case "prove_goal": + return trafficCaptureOffProveGoalNote + case "report_finding": + return trafficCaptureOffReportFindingNote + default: + return "" + } +} + // Applied after ToolResolve: user descriptions and prompts remain intact, while // all actual reporters (including Planner and custom chat agents) see the same // API contract. Disabled/unbound tools are never reintroduced here. @@ -56,16 +100,27 @@ func findingWorkflowTools(agentKey string, tools []actool.CoreTool) ([]actool.Co if agentKey == "reporter" && (tool.Name() == "traffic_search" || tool.Name() == "traffic_get" || tool.Name() == "traffic_blob" || tool.Name() == "traffic_messages") { continue } + desc := tool.Description() + schema := tool.InputSchema() + decorated := false switch tool.Name() { case "report_finding", "add_hint", "add_task_hint": // Work on a copy: toggling back on must restore the original schema. raw, _ := json.Marshal(tool.InputSchema()) - var schema map[string]any - if json.Unmarshal(raw, &schema) == nil { - stripTrafficParameters(schema) - tool = DecorateTool(tool, tool.Description(), schema) + var s map[string]any + if json.Unmarshal(raw, &s) == nil { + stripTrafficParameters(s) + schema = s + decorated = true } } + if note := trafficCaptureOffToolNote(tool.Name()); note != "" { + desc += note + decorated = true + } + if decorated { + tool = DecorateTool(tool, desc, schema) + } out = append(out, tool) } return out, "" @@ -83,6 +138,9 @@ 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 != "" { + note += capNote + } if note != "" { out[i] = DecorateTool(tool, tool.Description()+note, tool.InputSchema()) } diff --git a/agent/finding_workflow_test.go b/agent/finding_workflow_test.go index c478f3d..0e8ca2d 100644 --- a/agent/finding_workflow_test.go +++ b/agent/finding_workflow_test.go @@ -70,3 +70,47 @@ func TestFindingWorkflowSharedAssemblyAndSwitch(t *testing.T) { t.Fatal("reintroduced disabled tool or its guidance") } } + +func TestFindingWorkflowToolsTrafficCaptureOffNotice(t *testing.T) { + oldPolicy, oldCapture, oldResolve, oldAugment := FindingTrafficBindingEnabled(), TrafficCaptureEnabled(), ToolResolve(), ToolAugment() + t.Cleanup(func() { + SetFindingTrafficBindingEnabled(oldPolicy) + SetTrafficCaptureEnabled(oldCapture) + SetToolResolve(oldResolve) + SetToolAugment(oldAugment) + }) + SetToolAugment(nil) + SetToolResolve(nil) + ts := NewToolSet(nil, "fixture") + base := []actool.CoreTool{ts.proveGoal(), ts.addFinding(), ts.addHint()} + + for _, binding := range []bool{false, true} { + SetFindingTrafficBindingEnabled(func() bool { return binding }) + + SetTrafficCaptureEnabled(func() bool { return false }) + outOff, _, clOff := AugmentTools(t.Context(), "planner", base) + clOff() + for _, tool := range outOff { + desc := tool.Description() + switch tool.Name() { + case "prove_goal", "report_finding": + if !strings.Contains(desc, "traffic capture is currently OFF") { + t.Fatalf("binding=%v %s: expected capture-off notice in description, got %q", binding, tool.Name(), desc) + } + case "add_hint": + if strings.Contains(desc, "traffic capture is currently OFF") { + t.Fatalf("binding=%v add_hint: unexpected capture-off notice", binding) + } + } + } + + SetTrafficCaptureEnabled(func() bool { return true }) + outOn, _, clOn := AugmentTools(t.Context(), "planner", base) + clOn() + for _, tool := range outOn { + if strings.Contains(tool.Description(), "traffic capture is currently OFF") { + t.Fatalf("binding=%v %s: unexpected capture-off notice when capture is ON", binding, tool.Name()) + } + } + } +} diff --git a/server/assembly.go b/server/assembly.go index 9fb0754..5711504 100644 --- a/server/assembly.go +++ b/server/assembly.go @@ -223,6 +223,7 @@ func seedPrompts(pg *db.DB) { // and default params get injected. MCP/skill/host tools have no row and pass through. func wireTools(pg *db.DB, domainReg map[string]actool.CoreTool) { agent.SetFindingTrafficBindingEnabled(func() bool { return pg.GetBool(settingAgentTrafficBinding, false) }) + agent.SetTrafficCaptureEnabled(func() bool { return pg.GetBool(settingTrafficCapture, false) }) // Seed the built-in domain tools (first-insert only; DO NOTHING preserves edits). // No startup prune: rows we didn't seed are left alone so future user-defined // custom tools (system=false, added via the UI) survive restarts. diff --git a/web/src/app/(auth)/setup/page.tsx b/web/src/app/(auth)/setup/page.tsx index 152bca3..6aa2fa0 100644 --- a/web/src/app/(auth)/setup/page.tsx +++ b/web/src/app/(auth)/setup/page.tsx @@ -139,6 +139,9 @@ export default function SetupPage() { > {loading ? t("Saving...") : t("Set password and sign in")} +
+ {t("Traffic capture is off by default. Enable it in System settings after setup if you need provable HTTP findings — captured traffic is required for findings to prove goals.")} +
)} diff --git a/web/src/app/(main)/dashboard/page.tsx b/web/src/app/(main)/dashboard/page.tsx index ddd64c6..6243e62 100644 --- a/web/src/app/(main)/dashboard/page.tsx +++ b/web/src/app/(main)/dashboard/page.tsx @@ -572,7 +572,9 @@ export default function DashboardPage() { {t("Recording")} > ) : ( - {t("Capture is off")} + + {t("Capture is off · required for provable findings")} + )} @@ -1164,19 +1166,29 @@ export default function DashboardPage() { -+ {t("Traffic capture is off: findings stay recorded, but captured HTTP traffic is required for provable findings.")}{" "} + + {t("Enable in settings")} + +
+ )}+ {t("Traffic capture is off: findings stay recorded, but captured HTTP traffic is required for provable findings.")} +
+ )}