Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

refactor(httpapi): replace argvHasFlag with slices.Contains (#347)

fx-kurumi8999893b91a2
diff --git a/internal/httpapi/agent_tool_native.go b/internal/httpapi/agent_tool_native.go
index 557b0fac..12bc617a 100644
--- a/internal/httpapi/agent_tool_native.go
+++ b/internal/httpapi/agent_tool_native.go
@@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "slices"
"strings"
"time"
@@ -126,10 +127,10 @@ func applyNativeToolSafety(argv []string, mode AgentToolMode) []string {
// --tools is a built-in allowlist. CodeBuddy also applies it to MCP tools,
// so listing Read/Grep/Glob or mcp__* globs hides submit_* and TAPD/工蜂.
argv = dropNativeArg(argv, "--tools")
- if !argvHasFlag(argv, "--disallowedTools") {
+ if !slices.Contains(argv, "--disallowedTools") {
argv = appendNativeArgs(argv, "--disallowedTools", nativeDisallowedTools)
}
- if !argvHasFlag(argv, "--strict-mcp-config") {
+ if !slices.Contains(argv, "--strict-mcp-config") {
argv = appendNativeArgs(argv, "--strict-mcp-config")
}
return argv
@@ -191,15 +192,6 @@ func replaceArgValue(argv []string, flag, value string) []string {
return out
}
-func argvHasFlag(argv []string, flag string) bool {
- for _, arg := range argv {
- if arg == flag {
- return true
- }
- }
- return false
-}
-
func argvFlagValue(argv []string, flag string) (string, bool) {
for i, arg := range argv {
if arg == flag && i+1 < len(argv) {
diff --git a/internal/httpapi/agent_tool_native_safety_test.go b/internal/httpapi/agent_tool_native_safety_test.go
new file mode 100644
index 00000000..184959c8
--- /dev/null
+++ b/internal/httpapi/agent_tool_native_safety_test.go
@@ -0,0 +1,38 @@
+package httpapi
+
+import (
+ "slices"
+ "testing"
+)
+
+func TestApplyNativeToolSafety(t *testing.T) {
+ cases := []struct {
+ name string
+ in []string
+ want []string
+ }{
+ {
+ name: "drops tools and appends safety flags before delimiter",
+ in: []string{"cli", "--tools", "Read,Grep", "--tools=Glob", "-p", "--", "prompt"},
+ want: []string{"cli", "-p", "--disallowedTools", nativeDisallowedTools, "--strict-mcp-config", "--", "prompt"},
+ },
+ {
+ name: "appends at end without delimiter",
+ in: []string{"cli"},
+ want: []string{"cli", "--disallowedTools", nativeDisallowedTools, "--strict-mcp-config"},
+ },
+ {
+ name: "keeps existing safety flags",
+ in: []string{"cli", "--disallowedTools", "Bash", "--strict-mcp-config", "--", "prompt"},
+ want: []string{"cli", "--disallowedTools", "Bash", "--strict-mcp-config", "--", "prompt"},
+ },
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ got := applyNativeToolSafety(slices.Clone(tc.in), AgentToolAssistant)
+ if !slices.Equal(got, tc.want) {
+ t.Fatalf("applyNativeToolSafety(%q) = %q, want %q", tc.in, got, tc.want)
+ }
+ })
+ }
+}
diff --git a/internal/httpapi/agent_tool_session_test.go b/internal/httpapi/agent_tool_session_test.go
index 6c7f47ab..505b3a1a 100644
--- a/internal/httpapi/agent_tool_session_test.go
+++ b/internal/httpapi/agent_tool_session_test.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"os"
+ "slices"
"strings"
"testing"
"time"
@@ -198,7 +199,7 @@ func TestNativeClarifyCommandKeepsReadAndSessionMCP(t *testing.T) {
if !ok || !strings.Contains(denied, "Bash") || !strings.Contains(denied, "Write") || !strings.Contains(denied, "Edit") {
t.Fatalf("dangerous tools not denied: %q argv=%v", denied, command.Argv)
}
- if !argvHasFlag(command.Argv, "--strict-mcp-config") {
+ if !slices.Contains(command.Argv, "--strict-mcp-config") {
t.Fatal("missing --strict-mcp-config")
}
if src, _ := argvFlagValue(command.Argv, "--setting-sources"); src != "none" {
diff --git a/internal/httpapi/assistant_notification_report_test.go b/internal/httpapi/assistant_notification_report_test.go
index 4f019ac3..dcb0a615 100644
--- a/internal/httpapi/assistant_notification_report_test.go
+++ b/internal/httpapi/assistant_notification_report_test.go
@@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"net/http/httptest"
+ "slices"
"strings"
"testing"
@@ -81,7 +82,7 @@ func TestSOPReportUsesResponsibleUserAndMCPSubmission(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if argvHasFlag(command.Argv, "--tools") || !argvHasFlag(command.Argv, "--strict-mcp-config") {
+ if slices.Contains(command.Argv, "--tools") || !slices.Contains(command.Argv, "--strict-mcp-config") {
t.Fatalf("MCP hidden: %v", command.Argv)
}
if !strings.Contains(strings.Join(command.Argv, " "), "Read,Grep,Glob") {