返回 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", initialPath?: string) => {
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 ...(initialPath ? { initialPath } : {}),
38 });
39 });
40
41 const openTurnVerification = useCommittedCommand((summary: WireCompletionSummary) => openTurnResult(summary, "checks"));
42 const openTurnChanges = useCommittedCommand((summary?: WireCompletionSummary, initialPath?: string) => {
43 if (summary) openTurnResult(summary, "changes", initialPath);
44 else { setVerificationRevealRequest(null); input.openChangedDock(); }
45 });
46 const closeTurnResult = useCommittedCommand(() => setVerificationRevealRequest(null));
47
48 useVerificationRevealReset({
49 activeTabId: input.activeTabId,
50 completionSummary: input.completionSummary,
51 sessionPath: input.sessionPath,
52 turnStartAt: input.turnStartAt,
53 reset: setVerificationRevealRequest,
54 });
55
56 return { verificationRevealRequest, openTurnVerification, openTurnChanges, closeTurnResult };
57 }
58
58 lines TYPESCRIPT