Explorar o código

fix(de-ai): 批量复核对比也只展示章节正文

旧任务的 source/candidate 可能含 frontmatter;复核面板统一用 extractDeAiChapterText 后再对比。

Co-authored-by: Cursor <cursoragent@cursor.com>
darknessomi hai 1 mes
pai
achega
4a81a7ace0

+ 2 - 1
src/components/novel/de-ai-batch-entry.spec.ts

@@ -25,7 +25,8 @@ describe("de-ai batch entry and settings", () => {
   it("keeps review tasks project-scoped and reuses the selected skill when regenerating", () => {
     expect(previewPanel).toContain("selectProjectDeAiTasks(deAiTasks, project?.path)")
     expect(previewPanel).toContain("skillContent,")
-    expect(previewPanel).toContain("buildDeAiRewriteMessages(task.sourceContent, task.skillContent)")
+    expect(previewPanel).toContain("extractDeAiChapterText(task.sourceContent)")
+    expect(previewPanel).toContain("buildDeAiRewriteMessages(source, task.skillContent)")
   })
 
   it("小说设置包含默认 3、范围 1–5 的批量并发设置", () => {

+ 8 - 2
src/components/novel/de-ai-batch-review-dialog.tsx

@@ -14,6 +14,7 @@ import {
   ResizablePanelGroup,
 } from "@/components/ui/resizable"
 import { AiChangeComparePanel } from "@/components/common/ai-change-compare-panel"
+import { extractDeAiChapterText } from "@/lib/chapter-selection"
 import type { DeAiBatchChapter, DeAiBatchTaskRecord } from "@/lib/novel/de-ai-batch/types"
 
 const CHAPTER_STATUS: Record<DeAiBatchChapter["status"], string> = {
@@ -90,9 +91,14 @@ export function DeAiBatchReviewDialog({
     ?? record?.chapters[0]
     ?? null
   const candidateDraft = chapter ? candidateDrafts[chapter.id] : undefined
-  const candidateContent = chapter && candidateDraft?.generation === chapter.generation
+  const rawCandidateContent = chapter && candidateDraft?.generation === chapter.generation
     ? candidateDraft.content
     : chapter?.candidateContent ?? ""
+  // 旧任务可能把 frontmatter 一并塞进 source/candidate;对比与编辑都只暴露正文。
+  const originalContent = extractDeAiChapterText(chapter?.sourceContent ?? "")
+  const candidateContent = candidateDraft?.generation === chapter?.generation
+    ? rawCandidateContent
+    : extractDeAiChapterText(rawCandidateContent)
   const candidateEditable = !pending && chapter?.status === "ready"
   const canConfirm = candidateEditable && !!candidateContent.trim()
   const canSaveDraft = !pending
@@ -126,7 +132,7 @@ export function DeAiBatchReviewDialog({
 
   const comparisonPanel = (
     <AiChangeComparePanel
-      originalContent={chapter?.sourceContent ?? ""}
+      originalContent={originalContent}
       modifiedContent={candidateContent}
       originalLabel={"原文"}
       modifiedLabel={"候选"}