Selected documents return to drafting, and advance asks the creator to acknowledge an open recheck mark. Co-authored-by: Cursor <cursoragent@cursor.com>
269 lines
11 KiB
Go
269 lines
11 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"
|
|
|
|
// DutyPolicySeparated 标准三职分离(缺省/空值等价)。
|
|
DutyPolicySeparated = "separated"
|
|
// DutyPolicyAuthorOnly 编制人兼任审核与批准。
|
|
DutyPolicyAuthorOnly = "author_only"
|
|
)
|
|
|
|
// 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"`
|
|
TaskTitle string `json:"task_title,omitempty"`
|
|
Enabled bool `json:"enabled"`
|
|
ApprovalConfigurable bool `json:"approval_configurable,omitempty"`
|
|
// DutyPolicy 逐文档职责模式;空或缺省按 separated 解读(omitempty 保证旧快照 hash 不变)。
|
|
DutyPolicy string `json:"duty_policy,omitempty"`
|
|
Duties DocDuty `json:"duties"`
|
|
}
|
|
|
|
// StagePlan 阶段裁剪与文档任务。
|
|
type StagePlan struct {
|
|
StageKey string `json:"stage_key"`
|
|
StageName string `json:"stage_name,omitempty"`
|
|
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"`
|
|
}
|
|
|
|
// GovernancePolicyCapability 系统级编制人兼任总授权对项目设置的精简投影。
|
|
type GovernancePolicyCapability struct {
|
|
Allowed bool `json:"allowed"`
|
|
Revision int64 `json:"revision"`
|
|
BlockedReason string `json:"blocked_reason,omitempty"`
|
|
}
|
|
|
|
// 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"`
|
|
AuthorOnlyPolicy GovernancePolicyCapability `json:"author_only_policy"`
|
|
}
|
|
|
|
// 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"`
|
|
}
|
|
|
|
// PreviewDocRef 预览中列出的例外文档。
|
|
type PreviewDocRef struct {
|
|
TaskKey string `json:"task_key"`
|
|
Title string `json:"title"`
|
|
AuthorUserID int64 `json:"author_user_id,omitempty"`
|
|
}
|
|
|
|
// 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"`
|
|
GovernedDocTasks int `json:"governed_doc_tasks"`
|
|
UnmanagedDocTasks int `json:"unmanaged_doc_tasks"`
|
|
AssignedDuties int `json:"assigned_duties"`
|
|
AuthorOnlyDocTasks int `json:"author_only_doc_tasks,omitempty"`
|
|
UnmanagedDocuments []PreviewDocRef `json:"unmanaged_documents,omitempty"`
|
|
AuthorOnlyDocuments []PreviewDocRef `json:"author_only_documents,omitempty"`
|
|
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"
|
|
InstanceTerminated = "terminated"
|
|
InstanceAwaitingStageConfirmation = "awaiting_stage_confirmation"
|
|
InstanceTerminationRequested = "termination_requested"
|
|
)
|
|
|
|
// IsLiveInstanceStatus 与 GetLiveInstance / HasLiveInstance 的 active 系过滤一致。
|
|
func IsLiveInstanceStatus(status string) bool {
|
|
switch status {
|
|
case InstanceActive, InstanceAwaitingStageConfirmation, InstanceTerminationRequested:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// IsClosedInstanceStatus completed/terminated — 仍需 ABAC 拒绝,不得当作「从未激活」。
|
|
func IsClosedInstanceStatus(status string) bool {
|
|
return status == InstanceCompleted || status == InstanceTerminated
|
|
}
|
|
|
|
// 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"`
|
|
ApprovalManaged bool `json:"approval_managed"`
|
|
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"`
|
|
RequiresRecheckAck bool `json:"requires_recheck_ack"`
|
|
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"`
|
|
// AcknowledgeRecheck records that the creator saw open recheck marks.
|
|
// It does not clear those marks.
|
|
AcknowledgeRecheck bool `json:"acknowledge_recheck"`
|
|
}
|
|
|
|
// 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"`
|
|
}
|