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.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
refactor(runtime): reuse dropArgWithValue in isolateCodeBuddyFlagsWithSource (#305) (#306)
fx-kurumicedd727112c8
diff --git a/internal/runtime/drop_arg_test.go b/internal/runtime/drop_arg_test.gonew file mode 100644index 00000000..e393674e--- /dev/null+++ b/internal/runtime/drop_arg_test.go@@ -0,0 +1,52 @@+package runtime++import (+ "reflect"+ "testing"+)++func TestDropArgWithValueRemovesEveryFlagAndForm(t *testing.T) {+ in := []string{"cli", "--resume", "s1", "-p", "--tools=Read", "--model", "m", "--tools", "Bash", "--resume=s2", "prompt"}+ got := dropArgWithValue(in, "--resume", "--tools")+ want := []string{"cli", "-p", "--model", "m", "prompt"}+ if !reflect.DeepEqual(got, want) {+ t.Fatalf("dropArgWithValue = %v, want %v", got, want)+ }+ if single := dropArgWithValue([]string{"cli", "--resume", "s1", "-p"}, "--resume"); !reflect.DeepEqual(single, []string{"cli", "-p"}) {+ t.Fatalf("single flag = %v", single)+ }+ if len(in) != 11 || in[1] != "--resume" {+ t.Fatalf("input mutated: %v", in)+ }+}++func TestIsolateCodeBuddyFlagsReplacesAllIsolationFlags(t *testing.T) {+ cases := []struct {+ name string+ in []string+ want []string+ }{+ {+ name: "binary head with separate and equals forms",+ in: []string{"codebuddy", "-p", "--plugin-dir", "/x", "--setting-sources=project", "--permission-mode=dontAsk", "--output-format", "stream-json"},+ want: []string{"codebuddy", "-p", "--output-format", "stream-json", "-y", "--permission-mode", "bypassPermissions", "--setting-sources", "none"},+ },+ {+ name: "no binary head keeps existing skip-permissions flag",+ in: []string{"--dangerously-skip-permissions", "--permission-mode", "plan", "-p"},+ want: []string{"--dangerously-skip-permissions", "-p", "--permission-mode", "bypassPermissions", "--setting-sources", "none"},+ },+ {+ name: "empty",+ in: nil,+ want: []string{"-y", "--permission-mode", "bypassPermissions", "--setting-sources", "none"},+ },+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ if got := isolateCodeBuddyFlagsWithSource(tc.in, "none"); !reflect.DeepEqual(got, tc.want) {+ t.Fatalf("got %v, want %v", got, tc.want)+ }+ })+ }+}diff --git a/internal/runtime/provider_codebuddy.go b/internal/runtime/provider_codebuddy.goindex 3d49264c..5ebac93c 100644--- a/internal/runtime/provider_codebuddy.go+++ b/internal/runtime/provider_codebuddy.go@@ -99,31 +99,10 @@ func isolateCodeBuddyFlags(args []string) []string {}func isolateCodeBuddyFlagsWithSource(args []string, settingSource string) []string {- start := 0- if len(args) > 0 && !strings.HasPrefix(args[0], "-") {- start = 1+ out := dropArgWithValue(args, "--setting-sources", "--permission-mode", "--plugin-dir")+ if !hasArg(out, "-y") && !hasArg(out, "--dangerously-skip-permissions") {+ out = append(out, "-y")}- head := append([]string{}, args[:start]...)- rest := make([]string, 0, len(args)-start+4)- skipNext := false- for _, arg := range args[start:] {- if skipNext {- skipNext = false- continue- }- if arg == "--setting-sources" || arg == "--permission-mode" || arg == "--plugin-dir" {- skipNext = true- continue- }- if strings.HasPrefix(arg, "--setting-sources=") || strings.HasPrefix(arg, "--permission-mode=") || strings.HasPrefix(arg, "--plugin-dir=") {- continue- }- rest = append(rest, arg)- }- if !hasArg(rest, "-y") && !hasArg(rest, "--dangerously-skip-permissions") {- rest = append(rest, "-y")- }- rest = append(rest, "--permission-mode", "bypassPermissions")- rest = append(rest, "--setting-sources", settingSource)- return append(head, rest...)+ out = append(out, "--permission-mode", "bypassPermissions")+ return append(out, "--setting-sources", settingSource)}diff --git a/internal/runtime/runner.go b/internal/runtime/runner.goindex cd0269d5..e14ed10f 100644--- a/internal/runtime/runner.go+++ b/internal/runtime/runner.go@@ -7,6 +7,7 @@ import ("fmt""os""path/filepath"+ "slices""strings""time""unicode/utf8"@@ -322,7 +323,9 @@ func hasArg(values []string, wanted string) bool {return false}-func dropArgWithValue(values []string, flag string) []string {+// dropArgWithValue removes every occurrence of the given flags together with+// their value, accepting both the "--flag value" and "--flag=value" forms.+func dropArgWithValue(values []string, flags ...string) []string {out := make([]string, 0, len(values))skip := falsefor _, value := range values {@@ -330,11 +333,11 @@ func dropArgWithValue(values []string, flag string) []string {skip = falsecontinue}- if value == flag {+ if slices.Contains(flags, value) {skip = truecontinue}- if strings.HasPrefix(value, flag+"=") {+ if slices.ContainsFunc(flags, func(flag string) bool { return strings.HasPrefix(value, flag+"=") }) {continue}out = append(out, value)