返回 DeepSeek-Reasonix
useTurnVerificationCommands.ts
根目录 / desktop / frontend / src / app-runtime / useTurnVerificationCommands.ts
1 import { useRef, useState } from "react";
2 import { useCommittedCommand } from "../lib/useCommittedCommand";
3 import type { WireCompletionSummary } from "../lib/types";
4 import type { WorkspaceVerificationRevealRequest } from "../components/WorkspacePanel";
5 import { useVerificationRevealReset } from "./useLocalUiLifecycles";
6
7 export type TurnVerificationCommandsInput = {
8 activeTabId: string | undefined;
9 turnStartAt: number;
10 completionSummary: WireCompletionSummary | undefined;
11 sessionPath?: string;
12 openChangedDock(): void;
13 };
14
15 /**
16 * Owns the turn-verification reveal chain: opening the changed-files dock,
17 * issuing a monotonically sequenced reveal request bound to the tab and turn
18 * that published it, and resetting the request whenever the tab, turn or
19 * session changes. Summary updates preserve the selected result. WorkspacePanel consumes the request;
20 * only the reveal lifecycle lives here.
21 */
22 export function useTurnVerificationCommands(input: TurnVerificationCommandsInput) {
23 const revealSequenceRef = useRef(0);
24 const [verificationRevealRequest, setVerificationRevealRequest] = useState<WorkspaceVerificationRevealRequest | null>(null);
25
26 const openTurnResult = useCommittedCommand((summary: WireCompletionSummary, view: "changes" | "checks") => {
27 input.openChangedDock();
28 revealSequenceRef.current += 1;
29 setVerificationRevealRequest({
30 id: revealSequenceRef.current,
31 summary,
32 tabId: input.activeTabId ?? "",
33 turnStartAt: input.turnStartAt,
34 currentSummary: input.completionSummary,
35 sessionPath: input.sessionPath,
36 view,
37 });
38 });
39
40 const openTurnVerification = useCommittedCommand((summary: WireCompletionSummary) => openTurnResult(summary, "checks"));
41 const openTurnChanges = useCommittedCommand((summary?: WireCompletionSummary) => {
42 if (summary) openTurnResult(summary, "changes");
43 else { setVerificationRevealRequest(null); input.openChangedDock(); }
44 });
45 const closeTurnResult = useCommittedCommand(() => setVerificationRevealRequest(null));
46
47 useVerificationRevealReset({
48 activeTabId: input.activeTabId,
49 completionSummary: input.completionSummary,
50 sessionPath: input.sessionPath,
51 turnStartAt: input.turnStartAt,
52 reset: setVerificationRevealRequest,
53 });
54
55 return { verificationRevealRequest, openTurnVerification, openTurnChanges, closeTurnResult };
56 }
57
57 lines TYPESCRIPT