Răsfoiți Sursa

feat(draft-review): chat-panel 接入 Stage E 草稿校验触发

- 在 Stage D 之后调用 runDraftReviewSkill
- 通过 useDraftReviewStore 推送 loading/reviewing/done/error 状态
- 仅在 write_chapter/continue_chapter 且已打开项目时触发
- 复用 main 现有 store/panel/tab-container,不引入新文件
Mochocyang 2 luni în urmă
părinte
comite
af1917548b
1 a modificat fișierele cu 35 adăugiri și 0 ștergeri
  1. 35 0
      src/components/chat/chat-panel.tsx

+ 35 - 0
src/components/chat/chat-panel.tsx

@@ -39,6 +39,8 @@ import {
 } from "@/lib/reference/providers"
 import type { ReferenceToken } from "@/lib/reference/types"
 import { runAiChatSession } from "@/lib/agent/ai-chat-session"
+import { runDraftReviewSkill } from "@/lib/agent/skills/draft-review-skill"
+import { useDraftReviewStore } from "@/stores/draft-review-store"
 import { ToolRegistry } from "@/lib/agent/registry"
 import { registerAllBuiltInTools } from "@/lib/agent/tools"
 import {
@@ -1848,6 +1850,39 @@ export function ChatPanel() {
                     }
                   })().catch((err) => console.error("[Stage D] 执行失败:", err))
                 }
+                // === Stage E: 草稿校验与修复(硬偏差) ===
+                // 仅在已打开项目时触发;未打开项目时跳过(避免空路径调用 skill)
+                if (chapterContent && !hasChapterPlanMarker && projectPath) {
+                  const draftChapterNumber = effectiveTaskRoute.chapterNumber ?? 0
+                  void (async () => {
+                    try {
+                      useDraftReviewStore.getState().startReview(chapterContent)
+                      useDraftReviewStore.getState().setPhase({
+                        stage: "loading",
+                        description: "正在读取记忆中心...",
+                        progress: 10,
+                      })
+                      const reviewResult = await runDraftReviewSkill(
+                        {
+                          projectPath,
+                          draftChapterText: chapterContent,
+                          draftChapterNumber,
+                          mode: "full",
+                        },
+                        { llmConfig: agentConfig?.llmConfig },
+                      )
+                      useDraftReviewStore.getState().setResult(reviewResult)
+                    } catch (err) {
+                      const message = err instanceof Error ? err.message : String(err)
+                      console.error("[Stage E] 草稿校验失败:", err)
+                      useDraftReviewStore.getState().setPhase({
+                        stage: "error",
+                        description: `校验失败:${message}`,
+                        progress: 100,
+                      })
+                    }
+                  })().catch((err) => console.error("[Stage E] 执行失败:", err))
+                }
               }
               contextTrace = finishTrace(contextTrace, "done")
             }