|
@@ -17,7 +17,6 @@ import {
|
|
|
SelectValue,
|
|
SelectValue,
|
|
|
} from "@/components/ui/select.js";
|
|
} from "@/components/ui/select.js";
|
|
|
import { useZCodeIntl } from "@/i18n/IntlProvider.js";
|
|
import { useZCodeIntl } from "@/i18n/IntlProvider.js";
|
|
|
-import { cn } from "@/components/lib/utils.js";
|
|
|
|
|
import { useTabStore } from "@/store/TabStoreProvider.js";
|
|
import { useTabStore } from "@/store/TabStoreProvider.js";
|
|
|
import { isWorkspaceTab } from "@/store/tabStore.js";
|
|
import { isWorkspaceTab } from "@/store/tabStore.js";
|
|
|
import { useLocalWorkspaceScopes } from "@/hooks/useLocalWorkspaceScopes.js";
|
|
import { useLocalWorkspaceScopes } from "@/hooks/useLocalWorkspaceScopes.js";
|
|
@@ -28,6 +27,10 @@ import {
|
|
|
useTaskDispatchAnalysis,
|
|
useTaskDispatchAnalysis,
|
|
|
type TaskDispatchTarget,
|
|
type TaskDispatchTarget,
|
|
|
} from "@/task-dispatch/useTaskDispatchAnalysis.js";
|
|
} from "@/task-dispatch/useTaskDispatchAnalysis.js";
|
|
|
|
|
+import {
|
|
|
|
|
+ useTaskDispatchExecutor,
|
|
|
|
|
+ type TaskDispatchExecTask,
|
|
|
|
|
+} from "@/task-dispatch/useTaskDispatchExecutor.js";
|
|
|
import {
|
|
import {
|
|
|
taskDispatchHistoryStore,
|
|
taskDispatchHistoryStore,
|
|
|
type TaskDispatchAnalysisRecord,
|
|
type TaskDispatchAnalysisRecord,
|
|
@@ -36,6 +39,7 @@ import {
|
|
|
TaskDispatchPlanList,
|
|
TaskDispatchPlanList,
|
|
|
type TaskDispatchDraft,
|
|
type TaskDispatchDraft,
|
|
|
} from "@/task-dispatch/TaskDispatchPlanList.js";
|
|
} from "@/task-dispatch/TaskDispatchPlanList.js";
|
|
|
|
|
+import { TaskDispatchHistoryAside } from "@/task-dispatch/TaskDispatchHistoryAside.js";
|
|
|
|
|
|
|
|
/** 模块内可选的项目目标(本地 + 远程 workspace)。 */
|
|
/** 模块内可选的项目目标(本地 + 远程 workspace)。 */
|
|
|
export interface TaskDispatchWorkspaceOption {
|
|
export interface TaskDispatchWorkspaceOption {
|
|
@@ -84,47 +88,33 @@ function planToDrafts(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 分析会话终态监听器:仅在活跃分析存在时挂载(hooks 不能条件调用,用子组件承载订阅)。
|
|
|
|
|
- * sessions-index 里该会话 phase 到终态 → 一次性回调 onTerminal。
|
|
|
|
|
|
|
+ * 会话终态监听器:仅在存在待监听会话时挂载(hooks 不能条件调用,用子组件承载订阅)。
|
|
|
|
|
+ * sessions-index 里任一目标会话 phase 到终态 → 每会话一次性回调 onTerminal。
|
|
|
*/
|
|
*/
|
|
|
-function TaskDispatchAnalysisWatcher({
|
|
|
|
|
|
|
+function TaskDispatchSessionWatcher({
|
|
|
target,
|
|
target,
|
|
|
- sessionId,
|
|
|
|
|
|
|
+ sessionIds,
|
|
|
onTerminal,
|
|
onTerminal,
|
|
|
}: {
|
|
}: {
|
|
|
target: TaskDispatchTarget;
|
|
target: TaskDispatchTarget;
|
|
|
- sessionId: string;
|
|
|
|
|
- onTerminal: (phase: string) => void;
|
|
|
|
|
|
|
+ sessionIds: string[];
|
|
|
|
|
+ onTerminal: (sessionId: string, phase: string) => void;
|
|
|
}) {
|
|
}) {
|
|
|
const { sessions } = useSessionsIndex(target.workspacePath, target.workspaceIdentity ?? undefined);
|
|
const { sessions } = useSessionsIndex(target.workspacePath, target.workspaceIdentity ?? undefined);
|
|
|
- const firedRef = useRef(false);
|
|
|
|
|
|
|
+ const firedRef = useRef<Set<string>>(new Set());
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- if (firedRef.current) return;
|
|
|
|
|
- const summary = sessions.find((session) => session.sessionId === sessionId);
|
|
|
|
|
- if (summary && isTerminalSessionPhase(summary.phase)) {
|
|
|
|
|
- firedRef.current = true;
|
|
|
|
|
- onTerminal(summary.phase);
|
|
|
|
|
|
|
+ if (sessionIds.length === 0) return;
|
|
|
|
|
+ for (const session of sessions) {
|
|
|
|
|
+ if (firedRef.current.has(session.sessionId)) continue;
|
|
|
|
|
+ if (sessionIds.includes(session.sessionId) && isTerminalSessionPhase(session.phase)) {
|
|
|
|
|
+ firedRef.current.add(session.sessionId);
|
|
|
|
|
+ onTerminal(session.sessionId, session.phase);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }, [sessions, sessionId, onTerminal]);
|
|
|
|
|
|
|
+ }, [sessions, sessionIds, onTerminal]);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function formatHistoryStatus(
|
|
|
|
|
- intl: ReturnType<typeof useZCodeIntl>["intl"],
|
|
|
|
|
- record: TaskDispatchAnalysisRecord,
|
|
|
|
|
-): string {
|
|
|
|
|
- if (record.status === "analyzing") {
|
|
|
|
|
- return intl.formatMessage({ id: "taskDispatch.module.historyStatusAnalyzing" });
|
|
|
|
|
- }
|
|
|
|
|
- if (record.status === "failed") {
|
|
|
|
|
- return intl.formatMessage({ id: "taskDispatch.module.historyStatusFailed" });
|
|
|
|
|
- }
|
|
|
|
|
- return intl.formatMessage(
|
|
|
|
|
- { id: "taskDispatch.module.historyStatusDone" },
|
|
|
|
|
- { count: record.plan?.tasks.length ?? 0 },
|
|
|
|
|
- );
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
export function TaskDispatchModule({
|
|
export function TaskDispatchModule({
|
|
|
workspaceOptions,
|
|
workspaceOptions,
|
|
|
}: {
|
|
}: {
|
|
@@ -217,6 +207,40 @@ export function TaskDispatchModule({
|
|
|
[],
|
|
[],
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ // ── M4:统一权限确认 + 分组分发执行 ──
|
|
|
|
|
+ const executor = useTaskDispatchExecutor();
|
|
|
|
|
+ const [executeMode, setExecuteMode] = useState<"execute" | "createOnly">("execute");
|
|
|
|
|
+ const checkedCount = drafts.filter((draft) => draft.checked).length;
|
|
|
|
|
+
|
|
|
|
|
+ const handleConfirmDispatch = useCallback(() => {
|
|
|
|
|
+ if (!selected || checkedCount === 0) return;
|
|
|
|
|
+ const tasks: TaskDispatchExecTask[] = drafts
|
|
|
|
|
+ .filter((draft) => draft.checked && draft.title.trim() && draft.prompt.trim())
|
|
|
|
|
+ .map((draft, index) => ({
|
|
|
|
|
+ id: draft.key || `task-${index}`,
|
|
|
|
|
+ title: draft.title.trim(),
|
|
|
|
|
+ prompt: draft.prompt.trim(),
|
|
|
|
|
+ ...(draft.parallelGroup !== undefined ? { parallelGroup: draft.parallelGroup } : {}),
|
|
|
|
|
+ }));
|
|
|
|
|
+ if (tasks.length === 0) return;
|
|
|
|
|
+ void executor.start(tasks, targetFromOption(selected), executeMode === "execute");
|
|
|
|
|
+ }, [checkedCount, drafts, executor, executeMode, selected, targetFromOption]);
|
|
|
|
|
+
|
|
|
|
|
+ const dispatchSessionIds = useMemo(
|
|
|
|
|
+ () =>
|
|
|
|
|
+ executor.state.results
|
|
|
|
|
+ .filter((item) => item.sessionId && item.status !== "failed")
|
|
|
|
|
+ .map((item) => item.sessionId as string),
|
|
|
|
|
+ [executor.state.results],
|
|
|
|
|
+ );
|
|
|
|
|
+ const handleDispatchTerminal = useCallback(
|
|
|
|
|
+ (sessionId: string) => {
|
|
|
|
|
+ executor.reportSessionTerminal(sessionId);
|
|
|
|
|
+ },
|
|
|
|
|
+ [executor],
|
|
|
|
|
+ );
|
|
|
|
|
+ const dispatchPhase = executor.state.phase;
|
|
|
|
|
+
|
|
|
const analyzing = activeAnalysis !== null && drafts.length === 0 && error === null;
|
|
const analyzing = activeAnalysis !== null && drafts.length === 0 && error === null;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -297,51 +321,100 @@ export function TaskDispatchModule({
|
|
|
)}
|
|
)}
|
|
|
</section>
|
|
</section>
|
|
|
{/* 侧区:模块会话历史(UI 注册表 + sessions-index 活性;spec §8 M3 口径)。 */}
|
|
{/* 侧区:模块会话历史(UI 注册表 + sessions-index 活性;spec §8 M3 口径)。 */}
|
|
|
- <aside className="flex w-72 shrink-0 flex-col border-l border-border">
|
|
|
|
|
- <div className="border-b border-border px-3 py-2 text-ui-sm font-medium text-foreground-subtle">
|
|
|
|
|
- {intl.formatMessage({ id: "taskDispatch.module.history" })}
|
|
|
|
|
|
|
+ <TaskDispatchHistoryAside records={historyForSelected} onLoad={handleLoadHistory} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ {/* 统一权限确认栏(spec §8):清单在主区勾选/编辑,此处一次确认权限范围与执行模式。 */}
|
|
|
|
|
+ {drafts.length > 0 && dispatchPhase === "idle" ? (
|
|
|
|
|
+ <footer className="flex shrink-0 flex-wrap items-center justify-between gap-2 border-t border-border px-4 py-2">
|
|
|
|
|
+ <div className="flex min-w-0 items-center gap-3">
|
|
|
|
|
+ <span className="text-ui-sm text-foreground">
|
|
|
|
|
+ {intl.formatMessage(
|
|
|
|
|
+ { id: "taskDispatch.module.selectedCount" },
|
|
|
|
|
+ { selected: checkedCount, total: drafts.length },
|
|
|
|
|
+ )}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <span className="truncate text-ui-caption text-foreground-subtle">
|
|
|
|
|
+ {intl.formatMessage({ id: "taskDispatch.module.permissionScopeHint" })}
|
|
|
|
|
+ </span>
|
|
|
</div>
|
|
</div>
|
|
|
- <div className="min-h-0 flex-1 overflow-y-auto p-2">
|
|
|
|
|
- {historyForSelected.length === 0 ? (
|
|
|
|
|
- <div className="flex h-full items-center justify-center p-3 text-ui-caption text-foreground-subtlest">
|
|
|
|
|
- {intl.formatMessage({ id: "taskDispatch.module.historyEmpty" })}
|
|
|
|
|
- </div>
|
|
|
|
|
- ) : (
|
|
|
|
|
- <ul className="flex flex-col gap-1">
|
|
|
|
|
- {historyForSelected.map((record) => (
|
|
|
|
|
- <li key={record.id}>
|
|
|
|
|
- <button
|
|
|
|
|
- type="button"
|
|
|
|
|
- onClick={() => handleLoadHistory(record)}
|
|
|
|
|
- disabled={record.status !== "done"}
|
|
|
|
|
- className={cn(
|
|
|
|
|
- "flex w-full flex-col gap-0.5 rounded-[var(--ui-radius,8px)] px-2 py-1.5 text-left",
|
|
|
|
|
- "hover:bg-surface-hover disabled:cursor-default disabled:opacity-70",
|
|
|
|
|
- )}
|
|
|
|
|
- >
|
|
|
|
|
- <span className="flex items-center gap-1 truncate text-ui-sm text-foreground">
|
|
|
|
|
- {record.status === "analyzing" ? (
|
|
|
|
|
- <Loader2 className="size-3 shrink-0 animate-spin" />
|
|
|
|
|
- ) : null}
|
|
|
|
|
- {record.workspaceLabel}
|
|
|
|
|
- </span>
|
|
|
|
|
- <span className="text-ui-caption text-foreground-subtle">
|
|
|
|
|
- {formatHistoryStatus(intl, record)} ·{" "}
|
|
|
|
|
- {new Date(record.createdAt).toLocaleString()}
|
|
|
|
|
- </span>
|
|
|
|
|
- </button>
|
|
|
|
|
- </li>
|
|
|
|
|
- ))}
|
|
|
|
|
- </ul>
|
|
|
|
|
- )}
|
|
|
|
|
|
|
+ <div className="flex items-center gap-2">
|
|
|
|
|
+ <Select
|
|
|
|
|
+ value={executeMode}
|
|
|
|
|
+ onValueChange={(value) => setExecuteMode(value as "execute" | "createOnly")}
|
|
|
|
|
+ >
|
|
|
|
|
+ <SelectTrigger className="h-8 w-[150px]" size="sm">
|
|
|
|
|
+ <SelectValue />
|
|
|
|
|
+ </SelectTrigger>
|
|
|
|
|
+ <SelectContent>
|
|
|
|
|
+ <SelectItem value="execute">
|
|
|
|
|
+ {intl.formatMessage({ id: "taskDispatch.module.executeMode" })}
|
|
|
|
|
+ </SelectItem>
|
|
|
|
|
+ <SelectItem value="createOnly">
|
|
|
|
|
+ {intl.formatMessage({ id: "taskDispatch.module.createOnly" })}
|
|
|
|
|
+ </SelectItem>
|
|
|
|
|
+ </SelectContent>
|
|
|
|
|
+ </Select>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ size="sm"
|
|
|
|
|
+ disabled={checkedCount === 0}
|
|
|
|
|
+ onClick={handleConfirmDispatch}
|
|
|
|
|
+ >
|
|
|
|
|
+ {intl.formatMessage({ id: "taskDispatch.module.confirmDispatch" })}
|
|
|
|
|
+ </Button>
|
|
|
</div>
|
|
</div>
|
|
|
- </aside>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ </footer>
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ {dispatchPhase === "running" ? (
|
|
|
|
|
+ <footer className="flex shrink-0 items-center gap-2 border-t border-border px-4 py-2 text-ui-sm text-foreground">
|
|
|
|
|
+ <Loader2 className="size-4 animate-spin" />
|
|
|
|
|
+ <span>
|
|
|
|
|
+ {intl.formatMessage(
|
|
|
|
|
+ { id: "taskDispatch.module.dispatchProgress" },
|
|
|
|
|
+ {
|
|
|
|
|
+ current: executor.state.completedGroups + 1,
|
|
|
|
|
+ total: executor.state.totalGroups,
|
|
|
|
|
+ },
|
|
|
|
|
+ )}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ {executor.state.currentGroupPending > 0 ? (
|
|
|
|
|
+ <span className="text-ui-caption text-foreground-subtle">
|
|
|
|
|
+ {intl.formatMessage(
|
|
|
|
|
+ { id: "taskDispatch.module.awaitingGroup" },
|
|
|
|
|
+ { count: executor.state.currentGroupPending },
|
|
|
|
|
+ )}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ </footer>
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ {dispatchPhase === "done" ? (
|
|
|
|
|
+ <footer className="flex shrink-0 items-center justify-between gap-2 border-t border-border px-4 py-2 text-ui-sm text-foreground">
|
|
|
|
|
+ <span>
|
|
|
|
|
+ {intl.formatMessage(
|
|
|
|
|
+ { id: "taskDispatch.module.dispatchDone" },
|
|
|
|
|
+ {
|
|
|
|
|
+ created: executor.state.results.filter((item) => item.status === "created").length,
|
|
|
|
|
+ started: executor.state.results.filter((item) => item.status === "started").length,
|
|
|
|
|
+ failed: executor.state.results.filter((item) => item.status === "failed").length,
|
|
|
|
|
+ },
|
|
|
|
|
+ )}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <Button size="sm" variant="ghost" onClick={executor.reset}>
|
|
|
|
|
+ {intl.formatMessage({ id: "taskDispatch.module.dispatchBack" })}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </footer>
|
|
|
|
|
+ ) : null}
|
|
|
{activeAnalysis ? (
|
|
{activeAnalysis ? (
|
|
|
- <TaskDispatchAnalysisWatcher
|
|
|
|
|
|
|
+ <TaskDispatchSessionWatcher
|
|
|
target={activeAnalysis.target}
|
|
target={activeAnalysis.target}
|
|
|
- sessionId={activeAnalysis.record.sessionId}
|
|
|
|
|
- onTerminal={handleTerminal}
|
|
|
|
|
|
|
+ sessionIds={[activeAnalysis.record.sessionId]}
|
|
|
|
|
+ onTerminal={(_sessionId, phase) => handleTerminal(phase)}
|
|
|
|
|
+ />
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ {dispatchPhase === "running" && selected && dispatchSessionIds.length > 0 ? (
|
|
|
|
|
+ <TaskDispatchSessionWatcher
|
|
|
|
|
+ target={selected}
|
|
|
|
|
+ sessionIds={dispatchSessionIds}
|
|
|
|
|
+ onTerminal={handleDispatchTerminal}
|
|
|
/>
|
|
/>
|
|
|
) : null}
|
|
) : null}
|
|
|
</div>
|
|
</div>
|