/** * 创建流程串联 * 将向导→章程→任务→看板→通知串联成完整流程 */ import { generateCharter, generateStakeholderRegister, ProjectData } from './charter'; import { HRManager } from './hr-manager'; import { ExperienceManager } from './experience-manager'; import { notifyProjectCreated, notifyMilestoneReminder, notifyRiskAlert, sendDecisionCard } from '../server/feishu'; import { createDecision, DECISION_TEMPLATES, getPendingDecisions } from './decision-cards'; import { getChecklistByPhase, getPhaseCompletion, ChecklistItem } from './checklists'; export interface FlowResult { step: string; status: 'success' | 'pending' | 'failed'; output?: Record; error?: string; } /** * 项目创建全流程 * * 1. 用户完成向导 → 收集项目数据 * 2. 生成项目章程 * 3. 生成干系人登记册 * 4. 触发任务拆解(HR管理员) * 5. 创建初始看板任务 * 6. 推送启动阶段检查清单 * 7. 发送飞书通知 */ export async function runProjectCreationFlow(data: ProjectData): Promise<{ charter: string; stakeholderRegister: string; initialTasks: ReturnType; checklist: ChecklistItem[]; notificationSent: boolean; decisionNeeded: boolean; }> { // Step 1: Generate charter const charter = generateCharter(data); // Step 2: Generate stakeholder register const stakeholderRegister = generateStakeholderRegister(data); // Step 3: HR Manager decomposes initial tasks const hrManager = new HRManager(); const initialTasks = hrManager.decompose('创建项目章程,识别干系人', { projectName: data.name, goal: data.goal, stakeholders: data.stakeholders, milestones: data.milestones, }); // Step 4: Experience Manager records const experienceManager = new ExperienceManager(); for (const task of initialTasks) { experienceManager.recordExecution({ taskId: task.id, agentId: 'hr-manager-001', atomicType: task.atomicType!, input: task.input, output: {}, score: 4, durationMs: 0, model: 'system', success: true, timestamp: new Date().toISOString(), }); } // Step 5: Get initiating phase checklist const checklist = getChecklistByPhase('initiating'); // Step 6: Send notification let notificationSent = false; try { await notifyProjectCreated(data.name, data.goal, 'ou_41d14aca8278e605d98e33b1221777e4', 'open_id'); notificationSent = true; } catch { notificationSent = false; } // Step 7: Create charter approval decision const decision = createDecision(DECISION_TEMPLATES.charterApproval(data.name)); return { charter, stakeholderRegister, initialTasks, checklist, notificationSent, decisionNeeded: decision.status === 'pending', }; } /** * 获取项目当前状态概览 */ export function getProjectOverview(projectId: string, data: ProjectData) { const initiatingChecklist = getChecklistByPhase('initiating'); const completion = getPhaseCompletion(initiatingChecklist); const experienceManager = new ExperienceManager(); const knowledge = experienceManager.getKnowledgeSummary(); return { project: { name: data.name, goal: data.goal, status: 'active', }, initiating: { checklist: completion, charterGenerated: !!data.goal, stakeholdersIdentified: data.stakeholders.length, milestonesSet: data.milestones.length, }, knowledge, pendingDecisions: getPendingDecisions().length, }; }