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 observationActivity from applyObservation (#456)
fx-kurumiaddd52a4ed7a
diff --git a/internal/engine/engine_observe.go b/internal/engine/engine_observe.goindex 5631a7e7..ad621523 100644--- a/internal/engine/engine_observe.go+++ b/internal/engine/engine_observe.go@@ -180,37 +180,8 @@ func (e *Engine) applyObservation(r *domain.Run, nodeID string, observation doma}metricsSideChannel := observation.Source.Adapter == observability.AdapterHooks || observation.Source.Adapter == observability.AdapterOTELif !metricsSideChannel {- switch observation.Category {- case "reasoning":- nr.Activity = "模型正在推理"- case "output":- nr.Activity = "模型正在生成输出"- case "tool":- if observation.Name == "tool.call" && (observation.Phase != "finish" || observation.Level == "error") {- nr.Activity = "调用工具:" + observation.Message- }- case "sandbox":- if observation.Name != "sandbox.closed" {- nr.Activity = observation.Message- }- case "process":- if observation.Name == "process.started" {- label := observation.Provider- if label == "" {- label = "执行器"- }- if observation.Model != "" {- label += " · " + observation.Model- }- nr.Activity = label + " 已启动"- } else {- nr.Activity = observation.Message- }- default:- nr.Activity = observation.Message- if nr.Activity == "" {- nr.Activity = observation.Name- }+ if activity, ok := observationActivity(observation); ok {+ nr.Activity = activity}if observation.Category == "tool" && observation.Name == "tool.call" && observation.Phase == "finish" {nr.ToolCalls++@@ -229,3 +200,42 @@ func (e *Engine) applyObservation(r *domain.Run, nodeID string, observation domar.Telemetry = append([]domain.TelemetryEvent(nil), r.Telemetry[len(r.Telemetry)-4000:]...)}}++// observationActivity derives the node activity text shown for an observation.+// ok is false when the observation must leave the current activity unchanged:+// a finished, successful tool call or a closed sandbox.+func observationActivity(observation domain.TelemetryEvent) (activity string, ok bool) {+ switch observation.Category {+ case "reasoning":+ return "模型正在推理", true+ case "output":+ return "模型正在生成输出", true+ case "tool":+ if observation.Name == "tool.call" && (observation.Phase != "finish" || observation.Level == "error") {+ return "调用工具:" + observation.Message, true+ }+ return "", false+ case "sandbox":+ if observation.Name != "sandbox.closed" {+ return observation.Message, true+ }+ return "", false+ case "process":+ if observation.Name != "process.started" {+ return observation.Message, true+ }+ label := observation.Provider+ if label == "" {+ label = "执行器"+ }+ if observation.Model != "" {+ label += " · " + observation.Model+ }+ return label + " 已启动", true+ default:+ if observation.Message != "" {+ return observation.Message, true+ }+ return observation.Name, true+ }+}diff --git a/internal/engine/observation_activity_test.go b/internal/engine/observation_activity_test.gonew file mode 100644index 00000000..ae75a16d--- /dev/null+++ b/internal/engine/observation_activity_test.go@@ -0,0 +1,39 @@+package engine++import (+ "testing"++ "agentflow/internal/domain"+)++func TestObservationActivity(t *testing.T) {+ cases := []struct {+ name string+ obs domain.TelemetryEvent+ want string+ wantOK bool+ }{+ {"reasoning", domain.TelemetryEvent{Category: "reasoning", Message: "ignored"}, "模型正在推理", true},+ {"output", domain.TelemetryEvent{Category: "output"}, "模型正在生成输出", true},+ {"tool start", domain.TelemetryEvent{Category: "tool", Name: "tool.call", Phase: "start", Message: "Bash"}, "调用工具:Bash", true},+ {"tool finish error", domain.TelemetryEvent{Category: "tool", Name: "tool.call", Phase: "finish", Level: "error", Message: "Bash"}, "调用工具:Bash", true},+ {"tool finish ok keeps activity", domain.TelemetryEvent{Category: "tool", Name: "tool.call", Phase: "finish", Message: "Bash"}, "", false},+ {"other tool event keeps activity", domain.TelemetryEvent{Category: "tool", Name: "tool.result", Message: "x"}, "", false},+ {"sandbox", domain.TelemetryEvent{Category: "sandbox", Name: "sandbox.ready", Message: "沙箱就绪"}, "沙箱就绪", true},+ {"sandbox closed keeps activity", domain.TelemetryEvent{Category: "sandbox", Name: "sandbox.closed", Message: "closed"}, "", false},+ {"process started default label", domain.TelemetryEvent{Category: "process", Name: "process.started"}, "执行器 已启动", true},+ {"process started provider model", domain.TelemetryEvent{Category: "process", Name: "process.started", Provider: "codex", Model: "gpt"}, "codex · gpt 已启动", true},+ {"process started model only", domain.TelemetryEvent{Category: "process", Name: "process.started", Model: "gpt"}, "执行器 · gpt 已启动", true},+ {"process other", domain.TelemetryEvent{Category: "process", Name: "process.stdout", Message: "line"}, "line", true},+ {"default message", domain.TelemetryEvent{Category: "verification", Name: "verify.done", Message: "验证通过"}, "验证通过", true},+ {"default falls back to name", domain.TelemetryEvent{Category: "custom", Name: "custom.event"}, "custom.event", true},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ got, ok := observationActivity(tc.obs)+ if got != tc.want || ok != tc.wantOK {+ t.Fatalf("observationActivity() = (%q, %v), want (%q, %v)", got, ok, tc.want, tc.wantOK)+ }+ })+ }+}