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(engine): extract promptRepositoryLine and upstreamNodeOutputs from applyPromptPlaceholders (#459)
fx-kurumib92762a8e7b1
diff --git a/internal/engine/prompt.go b/internal/engine/prompt.goindex 191974c0..d011234a 100644--- a/internal/engine/prompt.go+++ b/internal/engine/prompt.go@@ -32,15 +32,7 @@ func applyPromptPlaceholders(st *repo.Store, wf domain.WorkflowDefinition, nodeprompt += "\n\n## 本次运行输入\n\n{{input}}"}prompt = strings.ReplaceAll(prompt, "{{input}}", run.Input)- repository := "未绑定代码仓库"- if run.Repository.RepositoryID != "" {- identity := run.Repository.GongfengProjectID- if run.Repository.Provider == domain.RepositoryProviderSSH {- identity = "Git SSH"- }- repository = fmt.Sprintf("%s (%s), 最新远端基线 %s, 本次工作分支 %s", run.Repository.Name, identity, run.Repository.BaseBranch, run.Repository.WorkBranch)- }- prompt = strings.ReplaceAll(prompt, "{{repository}}", repository)+ prompt = strings.ReplaceAll(prompt, "{{repository}}", promptRepositoryLine(run))pipelineURL := "未配置 Pipeline"if run.Repository.PipelineURLPattern != "" {pipelineURL = strings.ReplaceAll(run.Repository.PipelineURLPattern, "{build_id}", "current")@@ -84,14 +76,7 @@ func applyPromptPlaceholders(st *repo.Store, wf domain.WorkflowDefinition, node}}}- upstream := []string{}- for _, edge := range wf.Edges {- if edge.Target == node.ID {- if source := run.Nodes[edge.Source]; source != nil && source.Output != "" {- upstream = append(upstream, fmt.Sprintf("[%s]\n%s", edge.Source, source.Output))- }- }- }+ upstream := upstreamNodeOutputs(wf, node, run)if len(upstream) > 0 && !strings.Contains(prompt, "{{upstream}}") {prompt += "\n\n## 上游节点输出\n\n{{upstream}}"}@@ -108,6 +93,34 @@ func applyPromptPlaceholders(st *repo.Store, wf domain.WorkflowDefinition, nodereturn prompt}+// promptRepositoryLine renders the {{repository}} placeholder value for the+// run's primary repository.+func promptRepositoryLine(run domain.Run) string {+ if run.Repository.RepositoryID == "" {+ return "未绑定代码仓库"+ }+ identity := run.Repository.GongfengProjectID+ if run.Repository.Provider == domain.RepositoryProviderSSH {+ identity = "Git SSH"+ }+ return fmt.Sprintf("%s (%s), 最新远端基线 %s, 本次工作分支 %s", run.Repository.Name, identity, run.Repository.BaseBranch, run.Repository.WorkBranch)+}++// upstreamNodeOutputs collects, in edge order, the non-empty outputs of the+// nodes feeding into node, each labelled with its source node ID.+func upstreamNodeOutputs(wf domain.WorkflowDefinition, node domain.WorkflowNode, run domain.Run) []string {+ upstream := []string{}+ for _, edge := range wf.Edges {+ if edge.Target != node.ID {+ continue+ }+ if source := run.Nodes[edge.Source]; source != nil && source.Output != "" {+ upstream = append(upstream, fmt.Sprintf("[%s]\n%s", edge.Source, source.Output))+ }+ }+ return upstream+}+func sshDeliveryHint(run domain.Run) string {var sshRepos []stringfor _, repository := range run.RepositoryContexts() {diff --git a/internal/engine/prompt_helpers_test.go b/internal/engine/prompt_helpers_test.gonew file mode 100644index 00000000..d4db4f2d--- /dev/null+++ b/internal/engine/prompt_helpers_test.go@@ -0,0 +1,58 @@+package engine++import (+ "reflect"+ "testing"++ "agentflow/internal/domain"+)++func TestPromptRepositoryLine(t *testing.T) {+ cases := []struct {+ name string+ repo domain.RepositoryContext+ want string+ }{+ {name: "unbound", want: "未绑定代码仓库"},+ {+ name: "gongfeng",+ repo: domain.RepositoryContext{RepositoryID: "r1", Name: "demo", GongfengProjectID: "123", BaseBranch: "main", WorkBranch: "feat/x"},+ want: "demo (123), 最新远端基线 main, 本次工作分支 feat/x",+ },+ {+ name: "ssh",+ repo: domain.RepositoryContext{RepositoryID: "r2", Name: "infra", Provider: domain.RepositoryProviderSSH, GongfengProjectID: "ignored", BaseBranch: "dev", WorkBranch: "w"},+ want: "infra (Git SSH), 最新远端基线 dev, 本次工作分支 w",+ },+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ if got := promptRepositoryLine(domain.Run{Repository: tc.repo}); got != tc.want {+ t.Fatalf("promptRepositoryLine() = %q, want %q", got, tc.want)+ }+ })+ }+}++func TestUpstreamNodeOutputs(t *testing.T) {+ node := domain.WorkflowNode{ID: "target"}+ wf := domain.WorkflowDefinition{Edges: []domain.WorkflowEdge{+ {Source: "b", Target: "target"},+ {Source: "empty", Target: "target"},+ {Source: "missing", Target: "target"},+ {Source: "a", Target: "other"},+ {Source: "a", Target: "target"},+ }}+ run := domain.Run{Nodes: map[string]*domain.NodeRun{+ "a": {Output: "out-a"},+ "b": {Output: "out-b"},+ "empty": {},+ }}+ want := []string{"[b]\nout-b", "[a]\nout-a"}+ if got := upstreamNodeOutputs(wf, node, run); !reflect.DeepEqual(got, want) {+ t.Fatalf("upstreamNodeOutputs() = %#v, want %#v", got, want)+ }+ if got := upstreamNodeOutputs(domain.WorkflowDefinition{}, node, run); got == nil || len(got) != 0 {+ t.Fatalf("no edges should yield empty non-nil slice, got %#v", got)+ }+}