Poll pending requests every 15 minutes, emit deduplicated escalation notifications, and close requests when creator confirms stage advance. Co-authored-by: Cursor <cursoragent@cursor.com>
216 lines
7.9 KiB
Go
216 lines
7.9 KiB
Go
package projectinstance
|
|
|
|
import (
|
|
"time"
|
|
|
|
"chat-agent-system/internal/workflowdef"
|
|
)
|
|
|
|
const (
|
|
LifecyclePlanning = "planning"
|
|
LifecycleActive = "active"
|
|
|
|
InstancePlanning = "planning"
|
|
InstanceActive = "active"
|
|
|
|
DutyAuthor = "author"
|
|
DutyReviewer = "reviewer"
|
|
DutyApprover = "approver"
|
|
)
|
|
|
|
// DocDuty 文档三权职责指派。
|
|
type DocDuty struct {
|
|
AuthorUserID int64 `json:"author_user_id,omitempty"`
|
|
ReviewerUserID int64 `json:"reviewer_user_id,omitempty"`
|
|
ApproverUserID int64 `json:"approver_user_id,omitempty"`
|
|
}
|
|
|
|
// DocTaskPlan 文档任务裁剪与职责。
|
|
type DocTaskPlan struct {
|
|
TaskKey string `json:"task_key"`
|
|
Enabled bool `json:"enabled"`
|
|
Duties DocDuty `json:"duties"`
|
|
}
|
|
|
|
// StagePlan 阶段裁剪与文档任务。
|
|
type StagePlan struct {
|
|
StageKey string `json:"stage_key"`
|
|
Enabled bool `json:"enabled"`
|
|
DocTasks []DocTaskPlan `json:"doc_tasks"`
|
|
}
|
|
|
|
// WorkflowPlan 项目工作流规划快照。
|
|
type WorkflowPlan struct {
|
|
WorkflowDefinitionKey string `json:"workflow_definition_key"`
|
|
WorkflowVersion int `json:"workflow_version"`
|
|
WorkflowVersionID int64 `json:"workflow_version_id,omitempty"`
|
|
Stages []StagePlan `json:"stages"`
|
|
}
|
|
|
|
// WorkflowInstance 项目工作流实例。
|
|
type WorkflowInstance struct {
|
|
ID int64 `json:"id"`
|
|
ProjectID int64 `json:"project_id"`
|
|
WorkflowVersionID int64 `json:"workflow_version_id"`
|
|
InstanceNo int `json:"instance_no"`
|
|
Status string `json:"status"`
|
|
ConfigRevision int `json:"config_revision"`
|
|
PlanHash string `json:"plan_hash"`
|
|
ConfigSnapshot WorkflowPlan `json:"config_snapshot"`
|
|
ActivatedBy *int64 `json:"activated_by,omitempty"`
|
|
ActivatedAt *time.Time `json:"activated_at,omitempty"`
|
|
CreatedBy *int64 `json:"created_by,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// ProjectSettings 项目设置聚合视图。
|
|
type ProjectSettings struct {
|
|
ProjectID int64 `json:"project_id"`
|
|
LifecycleStatus string `json:"lifecycle_status"`
|
|
ActiveWorkflowKey string `json:"active_workflow_key"`
|
|
WorkflowSelectionVersion int `json:"workflow_selection_version"`
|
|
WorkflowPlanRevision int `json:"workflow_plan_revision"`
|
|
Plan *WorkflowPlan `json:"plan,omitempty"`
|
|
PlanningInstance *WorkflowInstance `json:"planning_instance,omitempty"`
|
|
LiveInstance *WorkflowInstance `json:"live_instance,omitempty"`
|
|
CanEditPlan bool `json:"can_edit_plan"`
|
|
CanActivate bool `json:"can_activate"`
|
|
ActiveStageKey string `json:"active_stage_key,omitempty"`
|
|
StageAdvanceReady bool `json:"stage_advance_ready,omitempty"`
|
|
PublishedWorkflows []PublishedOption `json:"published_workflows,omitempty"`
|
|
}
|
|
|
|
// PublishedOption 可选已发布工作流。
|
|
type PublishedOption struct {
|
|
DefinitionKey string `json:"definition_key"`
|
|
DefinitionName string `json:"definition_name"`
|
|
LatestVersion int `json:"latest_version"`
|
|
WorkflowVersion int64 `json:"workflow_version_id"`
|
|
ProductDomain string `json:"product_domain,omitempty"`
|
|
}
|
|
|
|
// SavePlanInput 保存工作流规划。
|
|
type SavePlanInput struct {
|
|
Plan WorkflowPlan `json:"plan"`
|
|
ExpectedPlanRevision int `json:"expected_plan_revision"`
|
|
ExpectedSelectionVersion int `json:"expected_selection_version"`
|
|
}
|
|
|
|
// ActivationPreview 激活预览与确认令牌。
|
|
type ActivationPreview struct {
|
|
ConfirmationToken string `json:"confirmation_token"`
|
|
PlanHash string `json:"plan_hash"`
|
|
ExpectedProjectVersion int `json:"expected_project_version"`
|
|
ExpectedPlanRevision int `json:"expected_plan_revision"`
|
|
Summary PreviewSummary `json:"summary"`
|
|
Validation workflowdef.ValidationResult `json:"validation"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
}
|
|
|
|
// PreviewSummary 激活影响摘要。
|
|
type PreviewSummary struct {
|
|
WorkflowName string `json:"workflow_name"`
|
|
WorkflowVersion int `json:"workflow_version"`
|
|
EnabledStages int `json:"enabled_stages"`
|
|
EnabledDocTasks int `json:"enabled_doc_tasks"`
|
|
AssignedDuties int `json:"assigned_duties"`
|
|
FirstStageKey string `json:"first_stage_key,omitempty"`
|
|
FirstStageName string `json:"first_stage_name,omitempty"`
|
|
}
|
|
|
|
// ActivateInput 二次确认激活。
|
|
type ActivateInput struct {
|
|
ConfirmationToken string `json:"confirmation_token"`
|
|
ExpectedProjectVersion int `json:"expected_project_version"`
|
|
ExpectedPlanRevision int `json:"expected_plan_revision"`
|
|
}
|
|
|
|
// ActivateResult 激活结果。
|
|
type ActivateResult struct {
|
|
ProjectID int64 `json:"project_id"`
|
|
LifecycleStatus string `json:"lifecycle_status"`
|
|
ActiveWorkflowKey string `json:"active_workflow_key"`
|
|
Instance WorkflowInstance `json:"instance"`
|
|
}
|
|
|
|
const (
|
|
StagePending = "pending"
|
|
StageActive = "active"
|
|
StageCompleted = "completed"
|
|
StageSkipped = "skipped"
|
|
|
|
InstanceCompleted = "completed"
|
|
)
|
|
|
|
// DocTaskInstance 文档任务运行实例。
|
|
type DocTaskInstance struct {
|
|
ID int64 `json:"id"`
|
|
TaskKey string `json:"task_key"`
|
|
Enabled bool `json:"enabled"`
|
|
Status string `json:"status"`
|
|
Approved bool `json:"approved"`
|
|
}
|
|
|
|
// StageInstance 阶段运行实例。
|
|
type StageInstance struct {
|
|
ID int64 `json:"id"`
|
|
StageKey string `json:"stage_key"`
|
|
Name string `json:"name,omitempty"`
|
|
Position int `json:"position"`
|
|
Enabled bool `json:"enabled"`
|
|
Status string `json:"status"`
|
|
DocTasks []DocTaskInstance `json:"doc_tasks,omitempty"`
|
|
}
|
|
|
|
// InstanceDetail 工作流实例详情(含阶段树)。
|
|
type InstanceDetail struct {
|
|
Instance WorkflowInstance `json:"instance"`
|
|
ActiveStageKey string `json:"active_stage_key,omitempty"`
|
|
Stages []StageInstance `json:"stages"`
|
|
}
|
|
|
|
// GateIssue 阶段门禁阻断项。
|
|
type GateIssue struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
TaskKey string `json:"task_key,omitempty"`
|
|
}
|
|
|
|
// DocTaskReadiness 文档任务就绪状态。
|
|
type DocTaskReadiness struct {
|
|
TaskKey string `json:"task_key"`
|
|
Required bool `json:"required"`
|
|
Enabled bool `json:"enabled"`
|
|
DocState string `json:"doc_state"`
|
|
Approved bool `json:"approved"`
|
|
}
|
|
|
|
// StageReadiness 阶段推进就绪评估。
|
|
type StageReadiness struct {
|
|
InstanceID int64 `json:"instance_id"`
|
|
StageKey string `json:"stage_key"`
|
|
StageName string `json:"stage_name"`
|
|
Ready bool `json:"ready"`
|
|
CanAdvance bool `json:"can_advance"`
|
|
BlockingIssues []GateIssue `json:"blocking_issues"`
|
|
DocTasks []DocTaskReadiness `json:"doc_tasks"`
|
|
ConfigRevision int `json:"config_revision"`
|
|
}
|
|
|
|
// AdvanceStageInput 创建者确认推进。
|
|
type AdvanceStageInput struct {
|
|
StageKey string `json:"stage_key"`
|
|
ExpectedConfigRevision int `json:"expected_config_revision"`
|
|
}
|
|
|
|
// AdvanceStageResult 阶段推进结果。
|
|
type AdvanceStageResult struct {
|
|
Instance WorkflowInstance `json:"instance"`
|
|
CompletedStage string `json:"completed_stage"`
|
|
CompletedStageInstanceID int64 `json:"completed_stage_instance_id,omitempty"`
|
|
CompletedReadinessRevision int `json:"completed_readiness_revision,omitempty"`
|
|
NextStageKey string `json:"next_stage_key,omitempty"`
|
|
InstanceDone bool `json:"instance_done"`
|
|
}
|