Files
Agent-System/internal/projectinstance/gate.go
T
weichenandCursor e0c39aa38c feat(service): add stage gate readiness and creator-confirmed advance.
Evaluate required document approvals before stage transition, expose readiness/advance APIs, show StageAdvanceBanner in the UI, and keep legacy workflow switch for explicit initial_workflow_key projects.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-13 02:50:23 +00:00

73 lines
1.7 KiB
Go

package projectinstance
import "chat-agent-system/internal/workflowdef"
func evaluateStageReadiness(
stagePlan StagePlan,
stageDef *workflowdef.StageDef,
docStates map[string]string,
) (bool, []GateIssue, []DocTaskReadiness) {
issues := make([]GateIssue, 0)
readiness := make([]DocTaskReadiness, 0)
if !stagePlan.Enabled {
return false, []GateIssue{{Code: "STAGE_DISABLED", Message: "阶段未启用"}}, readiness
}
taskDefMap := map[string]workflowdef.DocTaskDef{}
if stageDef != nil {
for _, dt := range stageDef.DocTasks {
taskDefMap[dt.Key] = dt
}
}
for _, dt := range stagePlan.DocTasks {
if !dt.Enabled {
continue
}
td, hasDef := taskDefMap[dt.TaskKey]
required := !hasDef || td.Required || td.Blocking
state := docStates[dt.TaskKey]
if state == "" {
state = "missing"
}
approved := state == "approved"
item := DocTaskReadiness{
TaskKey: dt.TaskKey,
Required: required,
Enabled: true,
DocState: state,
Approved: approved,
}
readiness = append(readiness, item)
if required && !approved {
msg := "必需文档尚未批准"
if state == "missing" {
msg = "必需文档尚未创建"
}
issues = append(issues, GateIssue{
Code: "DOC_NOT_APPROVED", TaskKey: dt.TaskKey, Message: msg,
})
}
}
return len(issues) == 0, issues, readiness
}
func findStagePlan(plan WorkflowPlan, stageKey string) *StagePlan {
for i := range plan.Stages {
if plan.Stages[i].StageKey == stageKey {
return &plan.Stages[i]
}
}
return nil
}
func findStageDef(def workflowdef.VersionDefinition, stageKey string) *workflowdef.StageDef {
for i := range def.Stages {
if def.Stages[i].Key == stageKey {
return &def.Stages[i]
}
}
return nil
}