Files
Agent-System/internal/projectworkflow/catalog.go
T

111 lines
3.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package projectworkflow
import "sync"
// Definition 工作流静态规范与契约定义
type Definition struct {
Key string `json:"key"`
Name string `json:"name"`
Description string `json:"description"`
StageKey string `json:"stage_key"`
TaskKey string `json:"task_key"`
RequiredUpstreamWorkflow string `json:"required_upstream_workflow,omitempty"`
OutputDocType string `json:"output_doc_type"`
OutputDocTitle string `json:"output_doc_title"`
Enabled bool `json:"enabled"`
}
// Catalog 工作流目录接口
type Catalog interface {
Get(workflowKey string) (*Definition, bool)
List() []*Definition
Validate() error
}
type memoryCatalog struct {
mu sync.RWMutex
definitions map[string]*Definition
order []string
}
// NewDefaultCatalog 创建默认工作流目录(内建 main、product_manager、test_manager)
func NewDefaultCatalog() Catalog {
c := &memoryCatalog{
definitions: make(map[string]*Definition),
order: []string{"main", "product_manager", "test_manager"},
}
c.definitions["main"] = &Definition{
Key: "main",
Name: "商务与研发综合主线",
Description: "覆盖从 V0.1 分诊到 V0.6 阶段评审的全流程智能体编排与商务研发主干协同",
StageKey: "main",
TaskKey: "main",
OutputDocType: "main_proposal",
OutputDocTitle: "商务研发综合方案",
Enabled: true,
}
c.definitions["product_manager"] = &Definition{
Key: "product_manager",
Name: "智能产品经理",
Description: "基于用户需求或项目上下文深度提炼,生成高可靠、可追溯的系统需求规格书",
StageKey: "system_reqs",
TaskKey: "system_reqs",
OutputDocType: "system_reqs",
OutputDocTitle: "系统需求规格书",
Enabled: true,
}
c.definitions["test_manager"] = &Definition{
Key: "test_manager",
Name: "智能测试经理",
Description: "依赖产品经理已批准的系统需求规格书,生成全覆盖、满足法规要求的系统验证方案及计划",
StageKey: "system_test_plan",
TaskKey: "test_manager",
RequiredUpstreamWorkflow: "product_manager",
OutputDocType: "system_test_plan",
OutputDocTitle: "系统验证方案及计划",
Enabled: true,
}
return c
}
func (c *memoryCatalog) Get(workflowKey string) (*Definition, bool) {
c.mu.RLock()
defer c.mu.RUnlock()
d, ok := c.definitions[workflowKey]
if !ok {
return nil, false
}
cpy := *d
return &cpy, true
}
func (c *memoryCatalog) List() []*Definition {
c.mu.RLock()
defer c.mu.RUnlock()
list := make([]*Definition, 0, len(c.order))
for _, key := range c.order {
if d, ok := c.definitions[key]; ok {
cpy := *d
list = append(list, &cpy)
}
}
return list
}
func (c *memoryCatalog) Validate() error {
c.mu.RLock()
defer c.mu.RUnlock()
for _, def := range c.definitions {
if def.RequiredUpstreamWorkflow != "" {
if _, ok := c.definitions[def.RequiredUpstreamWorkflow]; !ok {
return ErrWorkflowNotFound
}
}
}
return nil
}