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(repo): extract nodeMetricStage from requirementPhaseMeasurements (#599)
fx-kurumi575fec462c67
diff --git a/internal/repo/delivery.go b/internal/repo/delivery.goindex d6748ad6..4840f200 100644--- a/internal/repo/delivery.go+++ b/internal/repo/delivery.go@@ -843,13 +843,7 @@ func requirementPhaseMeasurements(run domain.Run, fallback domain.WorkflowDefiniif definition.Type == "sop" {continue}- stage, source := strings.TrimSpace(definition.MetricStage), "explicit"- if !frozenDefinition {- source = "inferred"- }- if stage == "" {- stage, source = inferLegacyMetricStage(nodeID, definition.Name, lane), "inferred"- }+ stage, source := nodeMetricStage(nodeID, definition, lane, frozenDefinition)if stage == "clarification" && (result.clarificationStart.IsZero() || nodeRun.StartedAt.Before(result.clarificationStart)) {result.clarificationStart, result.clarificationStartSource = nodeRun.StartedAt, source}@@ -892,6 +886,20 @@ func requirementPhaseMeasurements(run domain.Run, fallback domain.WorkflowDefinireturn result}+// nodeMetricStage resolves which requirement phase a node counts toward and+// where that answer came from. An explicit MetricStage is "explicit" only when+// it was read from the Run's frozen workflow snapshot; a blank one falls back+// to inferring the stage from the node ID, name and lane.+func nodeMetricStage(nodeID string, definition domain.WorkflowNode, lane string, frozenDefinition bool) (stage, source string) {+ if stage = strings.TrimSpace(definition.MetricStage); stage == "" {+ return inferLegacyMetricStage(nodeID, definition.Name, lane), "inferred"+ }+ if !frozenDefinition {+ return stage, "inferred"+ }+ return stage, "explicit"+}+func inferLegacyMetricStage(nodeID, name, lane string) string {text := strings.ToLower(strings.TrimSpace(nodeID + " " + name))switch {diff --git a/internal/repo/delivery_metric_stage_test.go b/internal/repo/delivery_metric_stage_test.gonew file mode 100644index 00000000..6e89257a--- /dev/null+++ b/internal/repo/delivery_metric_stage_test.go@@ -0,0 +1,77 @@+package repo++import (+ "testing"++ "agentflow/internal/domain"+)++func TestNodeMetricStage(t *testing.T) {+ cases := []struct {+ name string+ nodeID string+ definition domain.WorkflowNode+ lane string+ frozen bool+ wantStage string+ wantSource string+ }{+ {+ name: "explicit stage from frozen snapshot",+ nodeID: "build",+ definition: domain.WorkflowNode{Name: "需求澄清", MetricStage: " development "},+ frozen: true,+ wantStage: "development",+ wantSource: "explicit",+ },+ {+ name: "explicit stage from live fallback definition is inferred",+ nodeID: "build",+ definition: domain.WorkflowNode{MetricStage: "testing"},+ frozen: false,+ wantStage: "testing",+ wantSource: "inferred",+ },+ {+ name: "explicit none is passed through",+ nodeID: "notify",+ definition: domain.WorkflowNode{Name: "测试通知", MetricStage: "none"},+ frozen: true,+ wantStage: "none",+ wantSource: "explicit",+ },+ {+ name: "blank stage on frozen snapshot falls back to name inference",+ nodeID: "verify",+ definition: domain.WorkflowNode{Name: "测试验证", MetricStage: " "},+ frozen: true,+ wantStage: "testing",+ wantSource: "inferred",+ },+ {+ name: "blank stage falls back to lane inference",+ nodeID: "draft",+ definition: domain.WorkflowNode{Name: "整理"},+ lane: domain.SOPLaneProduct,+ frozen: true,+ wantStage: "clarification",+ wantSource: "inferred",+ },+ {+ name: "unrecognised node stays unclassified",+ nodeID: "misc",+ definition: domain.WorkflowNode{Name: "杂项"},+ frozen: false,+ wantStage: "",+ wantSource: "inferred",+ },+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ stage, source := nodeMetricStage(tc.nodeID, tc.definition, tc.lane, tc.frozen)+ if stage != tc.wantStage || source != tc.wantSource {+ t.Fatalf("nodeMetricStage() = (%q, %q), want (%q, %q)", stage, source, tc.wantStage, tc.wantSource)+ }+ })+ }+}