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): share Codex user provider argv between bindCommand and runner (#493) (#495)
fx-kurumi4cfba041ce4f
diff --git a/internal/runner/daemon.go b/internal/runner/daemon.goindex 7c0a4181..279e39d5 100644--- a/internal/runner/daemon.go+++ b/internal/runner/daemon.go@@ -12,7 +12,6 @@ import ("path/filepath"goruntime "runtime""slices"- "strconv""strings""sync""sync/atomic"@@ -1045,24 +1044,11 @@ func bindInvocationCredentials(inv *domain.RunnerInvocation, bindings []runtime.return nil, nil, errors.New("Codex 个人 API Key 未配置")}env["CODEX_API_KEY"] = key- baseURL := strings.TrimSpace(inv.CodexBaseURL)- if baseURL == "" {- baseURL = "https://api.openai.com/v1"- }- if len(argv) < 2 {- return nil, nil, errors.New("invalid Codex invocation")- }- config := []string{- "-c", `model_provider="agentflow_user"`,- "-c", `model_providers.agentflow_user.name="User API"`,- "-c", "model_providers.agentflow_user.base_url=" + strconv.Quote(baseURL),- "-c", `model_providers.agentflow_user.env_key="CODEX_API_KEY"`,- "-c", `model_providers.agentflow_user.wire_api="responses"`,- "-c", "model_providers.agentflow_user.requires_openai_auth=false",+ withProvider, err := runtime.CodexUserProviderArgv(argv, inv.CodexBaseURL)+ if err != nil {+ return nil, nil, err}- args := append([]string{}, argv[:len(argv)-1]...)- args = append(args, config...)- argv = append(args, argv[len(argv)-1])+ argv = withProvidercase runtime.BindClaudeCode:if !personal {continuediff --git a/internal/runtime/codex_user_provider_test.go b/internal/runtime/codex_user_provider_test.gonew file mode 100644index 00000000..eb5f3a1a--- /dev/null+++ b/internal/runtime/codex_user_provider_test.go@@ -0,0 +1,54 @@+package runtime++import (+ "slices"+ "testing"+)++func TestCodexUserProviderArgvInsertsProviderBeforePrompt(t *testing.T) {+ providerArgs := func(baseURL string) []string {+ return []string{+ "-c", `model_provider="agentflow_user"`,+ "-c", `model_providers.agentflow_user.name="User API"`,+ "-c", `model_providers.agentflow_user.base_url="` + baseURL + `"`,+ "-c", `model_providers.agentflow_user.env_key="CODEX_API_KEY"`,+ "-c", `model_providers.agentflow_user.wire_api="responses"`,+ "-c", "model_providers.agentflow_user.requires_openai_auth=false",+ }+ }+ cases := []struct {+ name string+ baseURL string+ wantURL string+ }{+ {"default base url", "", "https://api.openai.com/v1"},+ {"blank base url", " ", "https://api.openai.com/v1"},+ {"custom base url is trimmed", " https://proxy.example/v1 ", "https://proxy.example/v1"},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ in := []string{"codex", "exec", "--json", "prompt"}+ original := slices.Clone(in)+ got, err := CodexUserProviderArgv(in, tc.baseURL)+ if err != nil {+ t.Fatal(err)+ }+ want := append([]string{"codex", "exec", "--json"}, providerArgs(tc.wantURL)...)+ want = append(want, "prompt")+ if !slices.Equal(got, want) {+ t.Fatalf("argv = %#v\nwant %#v", got, want)+ }+ if !slices.Equal(in, original) {+ t.Fatalf("input argv was modified: %#v", in)+ }+ })+ }+}++func TestCodexUserProviderArgvRejectsShortInvocation(t *testing.T) {+ for _, argv := range [][]string{nil, {"codex"}} {+ if _, err := CodexUserProviderArgv(argv, ""); err == nil || err.Error() != "invalid Codex invocation" {+ t.Fatalf("CodexUserProviderArgv(%#v) error = %v, want invalid Codex invocation", argv, err)+ }+ }+}diff --git a/internal/runtime/command_binding.go b/internal/runtime/command_binding.goindex bc5de3e0..9ebeecfb 100644--- a/internal/runtime/command_binding.go+++ b/internal/runtime/command_binding.go@@ -97,26 +97,11 @@ func bindCommand(sandbox Sandbox, workspace string, command CommandSpec, credentif bound.environment["CODEX_API_KEY"] == "" {return CommandSpec{}, fmt.Errorf("需求责任人未配置 Codex API Key,请在个人配置中配置")}- baseURL := strings.TrimSpace(credentials.Codex.BaseURL)- if baseURL == "" {- baseURL = "https://api.openai.com/v1"- }- // The key stays in the process environment; only its variable name is- // written to argv. A dedicated provider prevents host login fallback.- config := []string{- "-c", `model_provider="agentflow_user"`,- "-c", `model_providers.agentflow_user.name="User API"`,- "-c", "model_providers.agentflow_user.base_url=" + strconv.Quote(baseURL),- "-c", `model_providers.agentflow_user.env_key="CODEX_API_KEY"`,- "-c", `model_providers.agentflow_user.wire_api="responses"`,- "-c", "model_providers.agentflow_user.requires_openai_auth=false",- }- if len(bound.Argv) < 2 {- return CommandSpec{}, fmt.Errorf("invalid Codex invocation")+ argv, err := CodexUserProviderArgv(bound.Argv, credentials.Codex.BaseURL)+ if err != nil {+ return CommandSpec{}, err}- args := append([]string{}, bound.Argv[:len(bound.Argv)-1]...)- args = append(args, config...)- bound.Argv = append(args, bound.Argv[len(bound.Argv)-1])+ bound.Argv = argvcase BindClaudeCode:bound.environment["ANTHROPIC_API_KEY"] = strings.TrimSpace(credentials.ClaudeCode.APIKey)if bound.environment["ANTHROPIC_API_KEY"] == "" {@@ -172,6 +157,33 @@ func bindCommand(sandbox Sandbox, workspace string, command CommandSpec, credentreturn bound, nil}+// CodexUserProviderArgv inserts a dedicated "agentflow_user" model provider+// before the final argv element (the prompt). An empty baseURL falls back to+// the OpenAI API. The key stays in the process environment as CODEX_API_KEY;+// only its variable name is written to argv, and the dedicated provider+// prevents a fallback to the host login. The input slice is not modified.+func CodexUserProviderArgv(argv []string, baseURL string) ([]string, error) {+ if len(argv) < 2 {+ return nil, fmt.Errorf("invalid Codex invocation")+ }+ baseURL = strings.TrimSpace(baseURL)+ if baseURL == "" {+ baseURL = "https://api.openai.com/v1"+ }+ config := []string{+ "-c", `model_provider="agentflow_user"`,+ "-c", `model_providers.agentflow_user.name="User API"`,+ "-c", "model_providers.agentflow_user.base_url=" + strconv.Quote(baseURL),+ "-c", `model_providers.agentflow_user.env_key="CODEX_API_KEY"`,+ "-c", `model_providers.agentflow_user.wire_api="responses"`,+ "-c", "model_providers.agentflow_user.requires_openai_auth=false",+ }+ out := make([]string, 0, len(argv)+len(config))+ out = append(out, argv[:len(argv)-1]...)+ out = append(out, config...)+ return append(out, argv[len(argv)-1]), nil+}+// PrivateHomeName is the directory under .agentflow/private-home that a// PrivateHome command runs with as HOME.func PrivateHomeName(command CommandSpec) string {