You've already forked agentic-coding-workflow
45 lines
2.7 KiB
TypeScript
45 lines
2.7 KiB
TypeScript
import type { Artifact, ArtifactPhase, Requirement } from '@/api/projects'
|
|
|
|
// 上一阶段产物注入 system prompt 的最大字符数,超出截断并标注。
|
|
const MAX_PREV_ARTIFACT_CHARS = 8000
|
|
|
|
// 三个 AI 对话阶段的角色模板。创建会话时与需求上下文拼接为 system prompt,
|
|
// 组装结果在创建表单中可见可改(前端组装方案,零后端耦合)。
|
|
export const PHASE_ROLE_PROMPTS: Record<ArtifactPhase, string> = {
|
|
planning: `你是一名资深产品规划助手。你的任务是与用户深入讨论需求,澄清目标、范围、用户场景与约束,最终形成一份结构化的规划文档(Markdown)。
|
|
讨论时主动提问补全缺失信息;输出规划文档时包含:背景与目标、范围(含不做什么)、用户场景、功能拆解、风险与依赖、验收标准。`,
|
|
prototyping: `你是一名资深原型设计助手。基于已确认的规划,与用户讨论并产出原型设计文档(Markdown)。
|
|
内容应包含:页面/界面结构、交互流程、状态与边界情况、数据展示与输入约束;可用文字线框、列表与表格描述布局。`,
|
|
auditing: `你是一名严格的方案评审助手。基于规划与原型,对方案进行评审并产出评审报告(Markdown)。
|
|
评审维度:完整性(是否覆盖规划目标)、一致性(原型与规划是否矛盾)、可行性(技术与排期风险)、边界情况遗漏、验收标准可测性。明确给出问题清单与修改建议,并给出评审结论(通过 / 有条件通过 / 不通过)。`,
|
|
}
|
|
|
|
// 上一阶段产物来源:prototyping ← planning、auditing ← prototyping、planning 无。
|
|
export const PREV_ARTIFACT_PHASE: Record<ArtifactPhase, ArtifactPhase | null> = {
|
|
planning: null,
|
|
prototyping: 'planning',
|
|
auditing: 'prototyping',
|
|
}
|
|
|
|
// buildRequirementSystemPrompt 组装阶段会话的 system prompt:
|
|
// 角色模板 + 需求标题/描述 + 上一阶段产物最新版(如有,超长截断)。
|
|
export function buildRequirementSystemPrompt(
|
|
phase: ArtifactPhase,
|
|
requirement: Pick<Requirement, 'number' | 'title' | 'description'>,
|
|
prevArtifact?: Artifact | null,
|
|
): string {
|
|
const parts: string[] = [PHASE_ROLE_PROMPTS[phase]]
|
|
parts.push(`## 当前需求\n需求 #${requirement.number}:${requirement.title}`)
|
|
if (requirement.description) {
|
|
parts.push(`### 需求描述\n${requirement.description}`)
|
|
}
|
|
if (prevArtifact) {
|
|
let content = prevArtifact.content
|
|
if (content.length > MAX_PREV_ARTIFACT_CHARS) {
|
|
content = content.slice(0, MAX_PREV_ARTIFACT_CHARS) + '\n\n……(内容过长,已截断)'
|
|
}
|
|
parts.push(`## 上一阶段(${prevArtifact.phase})产物 v${prevArtifact.version}\n${content}`)
|
|
}
|
|
return parts.join('\n\n')
|
|
}
|