UNPKG

taskflow-ai

Version:

TaskFlow AI - 智能PRD文档解析与任务管理助手,支持多模型AI协同、MCP编辑器集成,专为开发团队设计的CLI工具

243 lines (242 loc) 5.83 kB
/** * 需求提取器 - 从文档中智能提取和分析需求 * 使用自然语言处理和模式匹配技术 */ import { Logger } from '../../infra/logger'; import { DocumentStructure } from './document-processor'; import { TaskPriority } from '../../types/task'; /** * 需求类型枚举 */ export declare enum RequirementType { FUNCTIONAL = "functional",// 功能需求 NON_FUNCTIONAL = "non_functional",// 非功能需求 BUSINESS = "business",// 业务需求 TECHNICAL = "technical",// 技术需求 USER_STORY = "user_story",// 用户故事 CONSTRAINT = "constraint",// 约束条件 ASSUMPTION = "assumption" } /** * 需求接口 */ export interface Requirement { id: string; title: string; description: string; type: RequirementType; priority: TaskPriority; category: string; source: string; dependencies: string[]; acceptanceCriteria: string[]; estimatedEffort: number; complexity: 'low' | 'medium' | 'high'; tags: string[]; stakeholders: string[]; businessValue: number; technicalRisk: number; metadata: RequirementMetadata; } /** * 需求元数据 */ export interface RequirementMetadata { extractedAt: Date; confidence: number; extractionMethod: string; keywords: string[]; relatedSections: string[]; } /** * 提取选项 */ export interface ExtractionOptions { includeUserStories?: boolean; detectDependencies?: boolean; estimateEffort?: boolean; analyzePriority?: boolean; extractAcceptanceCriteria?: boolean; detectStakeholders?: boolean; } /** * 需求提取结果 */ export interface ExtractionResult { requirements: Requirement[]; summary: ExtractionSummary; warnings: string[]; suggestions: string[]; } /** * 提取摘要 */ export interface ExtractionSummary { totalRequirements: number; functionalRequirements: number; nonFunctionalRequirements: number; userStories: number; highPriorityRequirements: number; estimatedTotalEffort: number; averageComplexity: string; coverageScore: number; } /** * 需求提取器类 */ export declare class RequirementExtractor { private logger; private readonly requirementPatterns; private readonly priorityKeywords; private readonly complexityKeywords; constructor(logger: Logger); /** * 从文档结构中提取需求 * @param documentStructure 文档结构 * @param options 提取选项 */ extractRequirements(documentStructure: DocumentStructure, options?: ExtractionOptions): Promise<ExtractionResult>; /** * 从单个章节提取需求 * @param section 文档章节 * @param options 提取选项 */ private extractFromSection; /** * 提取功能需求 * @param section 章节 * @param content 内容 */ private extractFunctionalRequirements; /** * 提取非功能需求 * @param section 章节 * @param content 内容 */ private extractNonFunctionalRequirements; /** * 提取功能特性需求 * @param section 章节 * @param content 内容 */ private extractFeatureRequirements; /** * 提取用户故事 * @param section 章节 * @param content 内容 */ private extractUserStories; /** * 提取技术需求 * @param section 章节 * @param content 内容 */ private extractTechnicalRequirements; /** * 提取通用需求 * @param section 章节 * @param content 内容 */ private extractGeneralRequirements; /** * 创建需求对象 * @param id 需求ID * @param title 标题 * @param description 描述 * @param type 类型 * @param section 来源章节 * @param content 章节内容 */ private createRequirement; /** * 分析优先级 * @param text 文本 */ private analyzePriority; /** * 分析复杂度 * @param text 文本 */ private analyzeComplexity; /** * 估算工作量 * @param description 描述 * @param type 类型 */ private estimateEffort; /** * 计算业务价值 * @param description 描述 * @param type 类型 */ private calculateBusinessValue; /** * 计算技术风险 * @param description 描述 * @param type 类型 */ private calculateTechnicalRisk; /** * 计算提取置信度 * @param description 描述 * @param type 类型 */ private calculateConfidence; /** * 提取验收标准 * @param description 描述 */ private extractAcceptanceCriteria; /** * 提取标签 * @param description 描述 */ private extractTags; /** * 提取干系人 * @param description 描述 */ private extractStakeholders; /** * 检测依赖关系 * @param requirements 需求列表 */ private detectDependencies; /** * 检查是否有依赖关系 * @param desc1 描述1 * @param desc2 描述2 */ private hasDependencyRelation; /** * 生成摘要 * @param requirements 需求列表 */ private generateSummary; /** * 生成建议 * @param requirements 需求列表 * @param summary 摘要 */ private generateSuggestions; /** * 验证需求 * @param requirements 需求列表 */ private validateRequirements; /** * 判断是否是功能描述 * @param line 文本行 */ private isFunctionDescription; /** * 判断是否像需求 * @param line 文本行 */ private isRequirementLike; /** * 提取标题 * @param text 文本 */ private extractTitle; }