import type { ActiveRun, KdQuestion } from "./types.ts"; export function formatQuestions(run: ActiveRun): string { const questions = run.questions ?? []; if (questions.length === 0) return "尚未记录 Harness 问题。"; return questions.map(formatQuestionCard).join("\n\n"); } export function formatRuns(runs: ActiveRun[], activeId?: string): string { if (runs.length === 0) return "当前项目没有需求记录。使用 /kd <需求> 开始。"; return runs .map((run) => [ `${run.id === activeId ? "*" : "-"} ${run.id}`, ` 需求:${run.goal ?? "未知"}`, ` 状态:${run.status ?? "active"} | 模式:${run.mode} | 阶段:${run.phase} | 产品:${run.profile?.product ?? run.product ?? "unknown"}`, ` 更新时间:${run.updatedAt ?? "未知"}`, ].join("\n"), ) .join("\n\n"); } export function formatQuestionCard(question: KdQuestion): string { const lines = [ `问题 ${question.id} [${question.status}${question.blocking ? ", blocking" : ""}]`, `阶段:${question.phase}`, `问题:${question.question}`, question.reason ? `原因:${question.reason}` : undefined, question.contextSummary ? `提问前上下文:${question.contextSummary}` : undefined, question.sourceRefs?.length ? `来源:${question.sourceRefs.join(";")}` : undefined, question.factLabel ? `事实标签:${question.factLabel}` : undefined, question.proposedFactValue ? `候选事实值:${question.proposedFactValue}` : undefined, question.choices?.length ? `选项:${question.choices.join(" | ")}` : undefined, question.answer ? `答案:${question.answer}` : undefined, question.status === "open" ? `回答方式:用户在下一条消息中回答,或使用 kd_answer_user action=answer id=${question.id} answer=<答案> 记录。` : undefined, ]; return lines.filter(Boolean).join("\n"); } export function formatQuestionArtifactLines(question: KdQuestion): string[] { return [ `- ${question.id} [${question.blocking ? "blocking" : "non-blocking"}] ${question.question}`, question.reason ? ` - 原因:${question.reason}` : undefined, question.contextSummary ? ` - 提问前上下文:${question.contextSummary}` : undefined, question.sourceRefs?.length ? ` - 来源:${question.sourceRefs.join(";")}` : undefined, question.factLabel ? ` - 事实标签:${question.factLabel}` : undefined, question.proposedFactValue ? ` - 候选事实值:${question.proposedFactValue}` : undefined, question.choices?.length ? ` - 选项:${question.choices.join(" | ")}` : undefined, " - 状态:open", ].filter(Boolean) as string[]; }