ソースを参照

feat(ui): 任务分发改为专属对话框——纯 UI 拆分 + 批量草稿任务(二次对齐形态)

按用户二次对齐(入口/交互/执行/位置四项全改):
- 新增 TaskDispatchDialog:粘贴清单→本地启发式拆分(编号/项目符号/空行分段,
  零模型调用)→可编辑/删除/勾选的任务卡片→一键批量创建草稿任务
- 执行语义:草稿创建后用户在 TaskList 点开哪个、发送哪个才跑(agent 只执行不整理)
- 入口:项目行 hover 图标按钮(与文件树同组,显眼位置)+ 更多菜单项,均开对话框
- 移除废弃的 dispatchPlannerPrompt 预填链路;spec §7-a 记录二次对齐形态
- agent 工具链(DispatchTasks S1-S4)保留为编程入口,不影响本入口

验证:root typecheck 通过;lint 0 error;workspaceSidebar 单测 18/18 通过
wubinggen 1 ヶ月 前
親
コミット
3ce27552

+ 13 - 1
docs/specs/workspace-task-dispatch.md

@@ -1,6 +1,6 @@
 # Workspace Task Dispatch(项目级任务分发)Spec
 
-状态:设计定稿(2026-10-18,与用户对齐后落稿),实现分片推进中。
+状态:设计定稿(2026-10-18 二次对齐:UI 形态改为纯 UI 拆分对话框,见 §7-a;agent 工具链保留为编程入口)。
 关联:`apps/zcode-cli/docs/design/v2/tool/00-tool-change-chain.md`(工具改动链路入口清单)。
 
 ## 1. 能力概述
@@ -70,6 +70,18 @@
 
 ## 7. UI 面
 
+### 7-a. 主入口(2026-10-18 二次对齐后的形态)
+
+**纯 UI 拆分,不走 agent 整理**:`TaskDispatchDialog`(packages/ui/src/TaskDispatchDialog.tsx)
+- 入口:项目行 hover 图标按钮(与文件树按钮同组)+ "更多"菜单项,均打开对话框;
+- 对话框:粘贴 bug 清单 → **本地确定性启发式**拆分(编号 `1.` `1、` `1)` / 项目符号 `- * •` /
+  空行分段;≥2 个标记行的段按标记逐项拆,标记行为标题、后续行归说明;否则整段一项);
+- 卡片可编辑标题/说明、可删除、可勾选;解析零模型调用;
+- 确认 → 循环 `onCreateTask({ initialPrompt, targetWorkspace })` 批量创建**草稿任务**;
+- 执行:用户在 TaskList 点开任务、发送即跑——agent 只负责执行,不参与整理。
+
+### 7-b. 确认弹窗(agent 工具路径)
+
 - 确认弹窗:标准 PermissionDialog 承载(reason 内含清单摘要);后续版本再做
   create-workflow 式富卡片(display union 四文件 lockstep,单独评审)。
 - 项目入口:`WorkspaceSidebar` 项目区"任务分发"按钮 → 打开当前 workspace 新对话并

+ 276 - 0
packages/ui/src/TaskDispatchDialog.tsx

@@ -0,0 +1,276 @@
+// ============================================================
+// TaskDispatchDialog —— 项目级任务分发(纯 UI 拆分,不走 agent 整理)
+// ============================================================
+// 设计:docs/specs/workspace-task-dispatch.md(2026-10-18 二次对齐后的 UI 形态)。
+// 交互合同:
+// - 贴入 bug 清单 → 启发式拆分为任务卡片(编号/项目符号/空行分段);
+// - 卡片可编辑标题与说明、可删除、可勾选;
+// - 确认后在目标 workspace 批量创建【草稿任务】(initialPrompt 预填,不自动发送);
+//   执行由用户在 TaskList 点开任务、发送即跑——agent 只负责执行,不参与整理。
+// 解析是确定性启发式:不做任何模型调用,结果可预期、可撤销(重新解析覆盖)。
+
+import { useMemo, useState } from "react";
+import { Trash2Icon } from "lucide-react";
+import { Button } from "@/components/ui/button.js";
+import { Checkbox } from "@/components/ui/checkbox.js";
+import {
+  Dialog,
+  DialogContent,
+  DialogFooter,
+  DialogHeader,
+  DialogTitle,
+} from "@/components/ui/dialog.js";
+import { Input } from "@/components/ui/input.js";
+import { Textarea } from "@/components/ui/textarea.js";
+import { useZCodeIntl } from "@/i18n/IntlProvider.js";
+import { logger } from "@/logger.js";
+
+const MAX_DISPATCH_TASKS = 50;
+
+export interface TaskDispatchDraft {
+  key: string;
+  title: string;
+  detail: string;
+  selected: boolean;
+}
+
+interface ParsedItem {
+  title: string;
+  detail: string;
+}
+
+const LIST_MARKER_PATTERN = /^\s*(?:\d+[.、)]|[-*•])\s*/;
+
+function isListMarkerLine(line: string): boolean {
+  return LIST_MARKER_PATTERN.test(line);
+}
+
+/**
+ * 确定性拆分启发式:
+ * 1. 按空行分段;
+ * 2. 段内出现 ≥2 个列表标记行(1. / 1) / 1、 / - / * / •)时按标记逐项拆,
+ *    标记行为标题、随后的非标记行归入该项说明;
+ * 3. 否则整段一项:首行为标题,其余为说明。
+ * 标题超长时截断到 60 字符(TaskList 展示友好),完整内容保留在说明里。
+ */
+export function parseTaskDraftsText(text: string): ParsedItem[] {
+  const blocks = text
+    .replace(/\r\n/g, "\n")
+    .split(/\n\s*\n/)
+    .map((block) => block.trim())
+    .filter(Boolean);
+
+  const items: ParsedItem[] = [];
+  for (const block of blocks) {
+    const lines = block.split("\n");
+    const markerCount = lines.filter(isListMarkerLine).length;
+    if (markerCount >= 2) {
+      let current: ParsedItem | null = null;
+      for (const line of lines) {
+        if (isListMarkerLine(line)) {
+          if (current) items.push(current);
+          const rawTitle = line.replace(LIST_MARKER_PATTERN, "").trim();
+          current = { title: rawTitle.slice(0, 60), detail: rawTitle };
+        } else if (current) {
+          const trimmed = line.trim();
+          current.detail = current.detail ? `${current.detail}\n${trimmed}` : trimmed;
+        }
+      }
+      if (current) items.push(current);
+    } else {
+      const [firstLine, ...rest] = lines;
+      const rawTitle = (firstLine ?? block).replace(LIST_MARKER_PATTERN, "").trim();
+      const detail = rest.map((line) => line.trim()).filter(Boolean).join("\n");
+      items.push({ title: rawTitle.slice(0, 60), detail: [rawTitle, detail].filter(Boolean).join("\n") });
+    }
+  }
+  return items.slice(0, MAX_DISPATCH_TASKS);
+}
+
+export function TaskDispatchDialog({
+  open,
+  target,
+  onOpenChange,
+  onCreateTask,
+}: {
+  open: boolean;
+  target: { workspacePath: string; workspaceIdentity?: string } | null;
+  onOpenChange: (open: boolean) => void;
+  onCreateTask: (request: {
+    initialPrompt: string;
+    targetWorkspace: { workspacePath: string; workspaceIdentity?: string };
+  }) => void;
+}) {
+  const { intl } = useZCodeIntl();
+  const [rawText, setRawText] = useState("");
+  const [drafts, setDrafts] = useState<TaskDispatchDraft[]>([]);
+
+  const selectedCount = useMemo(
+    () => drafts.filter((draft) => draft.selected).length,
+    [drafts],
+  );
+
+  const parse = () => {
+    const parsed = parseTaskDraftsText(rawText);
+    setDrafts(
+      parsed.map((item, index) => ({
+        key: `draft-${index}-${item.title.slice(0, 12)}`,
+        title: item.title,
+        detail: item.detail,
+        selected: true,
+      })),
+    );
+    if (parsed.length === 0) {
+      logger.info("[TaskDispatchDialog] 解析结果为空", { rawLength: rawText.length });
+    }
+  };
+
+  const reset = () => {
+    setRawText("");
+    setDrafts([]);
+  };
+
+  const confirm = () => {
+    if (!target) return;
+    const chosen = drafts.filter((draft) => draft.selected && draft.title.trim());
+    for (const draft of chosen) {
+      onCreateTask({
+        // 预填正文 = 标题 + 完整说明;用户点开任务发送后由 agent 执行。
+        initialPrompt: draft.detail.trim() || draft.title.trim(),
+        targetWorkspace: {
+          workspacePath: target.workspacePath,
+          ...(target.workspaceIdentity ? { workspaceIdentity: target.workspaceIdentity } : {}),
+        },
+      });
+    }
+    logger.info("[TaskDispatchDialog] 批量创建草稿任务完成", {
+      requested: chosen.length,
+      workspacePath: target.workspacePath,
+    });
+    reset();
+    onOpenChange(false);
+  };
+
+  return (
+    <Dialog
+      open={open}
+      onOpenChange={(next) => {
+        if (!next) reset();
+        onOpenChange(next);
+      }}
+    >
+      <DialogContent className="flex max-h-[85vh] w-[min(680px,92vw)] max-w-none flex-col overflow-hidden rounded-2xl p-0">
+        <div className="flex min-h-0 flex-1 flex-col gap-4 p-6">
+          <DialogHeader>
+            <DialogTitle>
+              {intl.formatMessage({ id: "taskDispatch.title" })}
+            </DialogTitle>
+          </DialogHeader>
+          {drafts.length === 0 ? (
+            <div className="flex min-h-0 flex-1 flex-col gap-3">
+              <Textarea
+                className="min-h-[220px] flex-1 resize-none font-mono text-ui-sm"
+                placeholder={intl.formatMessage({ id: "taskDispatch.pastePlaceholder" })}
+                value={rawText}
+                onChange={(event) => setRawText(event.target.value)}
+              />
+              <div className="flex items-center justify-between gap-3">
+                <p className="text-ui-caption text-foreground-subtle">
+                  {intl.formatMessage({ id: "taskDispatch.parseHint" })}
+                </p>
+                <Button
+                  size="sm"
+                  disabled={!rawText.trim()}
+                  onClick={parse}
+                >
+                  {intl.formatMessage({ id: "taskDispatch.parse" })}
+                </Button>
+              </div>
+            </div>
+          ) : (
+            <div className="flex min-h-0 flex-1 flex-col gap-3">
+              <div className="flex items-center justify-between">
+                <p className="text-ui-caption text-foreground-subtle">
+                  {intl.formatMessage(
+                    { id: "taskDispatch.selectedCount" },
+                    { selected: selectedCount, total: drafts.length },
+                  )}
+                </p>
+                <div className="flex gap-2">
+                  <Button variant="ghost" size="sm" onClick={reset}>
+                    {intl.formatMessage({ id: "taskDispatch.reparse" })}
+                  </Button>
+                </div>
+              </div>
+              <div className="flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto pr-1">
+                {drafts.map((draft, index) => (
+                  <div
+                    key={draft.key}
+                    className="flex flex-col gap-2 rounded-xl border border-border p-3"
+                  >
+                    <div className="flex items-center gap-2">
+                      <Checkbox
+                        checked={draft.selected}
+                        onCheckedChange={(checked) => {
+                          setDrafts((prev) =>
+                            prev.map((item, i) =>
+                              i === index ? { ...item, selected: checked === true } : item,
+                            ),
+                          );
+                        }}
+                      />
+                      <Input
+                        className="h-8 flex-1"
+                        value={draft.title}
+                        onChange={(event) => {
+                          const value = event.target.value;
+                          setDrafts((prev) =>
+                            prev.map((item, i) => (i === index ? { ...item, title: value } : item)),
+                          );
+                        }}
+                      />
+                      <Button
+                        variant="ghost"
+                        size="icon-sm"
+                        aria-label={intl.formatMessage({ id: "taskDispatch.remove" })}
+                        onClick={() => {
+                          setDrafts((prev) => prev.filter((_, i) => i !== index));
+                        }}
+                      >
+                        <Trash2Icon className="h-3.5 w-3.5" />
+                      </Button>
+                    </div>
+                    <Textarea
+                      className="min-h-[52px] resize-none text-ui-sm"
+                      value={draft.detail}
+                      onChange={(event) => {
+                        const value = event.target.value;
+                        setDrafts((prev) =>
+                          prev.map((item, i) => (i === index ? { ...item, detail: value } : item)),
+                        );
+                      }}
+                    />
+                  </div>
+                ))}
+              </div>
+            </div>
+          )}
+        </div>
+        <DialogFooter className="border-t border-border p-4">
+          <Button variant="ghost" onClick={() => onOpenChange(false)}>
+            {intl.formatMessage({ id: "common.cancel" })}
+          </Button>
+          <Button
+            disabled={drafts.length === 0 || selectedCount === 0}
+            onClick={confirm}
+          >
+            {intl.formatMessage(
+              { id: "taskDispatch.createDrafts" },
+              { count: selectedCount },
+            )}
+          </Button>
+        </DialogFooter>
+      </DialogContent>
+    </Dialog>
+  );
+}

+ 18 - 17
packages/ui/src/WorkspaceSidebar.tsx

@@ -114,6 +114,7 @@ import type { Theme } from "@/useTheme.js";
 import type { RemoteConnectionLogEntry } from "@/hooks/useRemoteConnectionLogs.js";
 import type { CodeViewerSource } from "@/lib/codeViewer.js";
 import { WorkspaceFileTree } from "@/WorkspaceFileTree.js";
+import { TaskDispatchDialog } from "@/TaskDispatchDialog.js";
 import { WorkspaceArchivedTasksFlatSection } from "@/WorkspaceArchivedTasksFlatSection.js";
 import { WebRemoteControlTaskIndex } from "@/WebRemoteControlTaskIndex.js";
 import { WorkspaceSidebarFooter } from "@/WorkspaceSidebarFooter.js";
@@ -407,6 +408,11 @@ export const WorkspaceSidebar = memo(function WorkspaceSidebarComponent({
   );
   const [isFileTreeOpen, setIsFileTreeOpen] = useState(false);
   const [fileTreeTarget, setFileTreeTarget] = useState<SidebarFileTreeTarget | null>(null);
+  // 任务分发对话框的目标 workspace(null = 关闭)。
+  const [taskDispatchTarget, setTaskDispatchTarget] = useState<{
+    workspacePath: string;
+    workspaceIdentity?: string;
+  } | null>(null);
   const [groupedStickyHeader, setGroupedStickyHeader] = useState<ReactNode | null>(null);
   const [taskOrganizeBy, setTaskOrganizeBy] = useState<TaskOrganizeBy>(
     () => readSidebarTaskPreferences().organizeBy,
@@ -1828,23 +1834,9 @@ export const WorkspaceSidebar = memo(function WorkspaceSidebarComponent({
                                               isWebRemoteControlSidebar
                                                 ? undefined
                                                 : (target) => {
-                                                    // 任务分收入口:在目标项目打开预填规划
-                                                    // 提示词的新任务草稿(只预填不发送),
-                                                    // 由 agent 整理清单后走 DispatchTools 工具。
-                                                    onCreateTask({
-                                                      initialPrompt: intl.formatMessage({
-                                                        id: "workspaceSidebar.dispatchPlannerPrompt",
-                                                      }),
-                                                      targetWorkspace: {
-                                                        workspacePath: target.workspacePath,
-                                                        ...(target.workspaceIdentity
-                                                          ? {
-                                                              workspaceIdentity:
-                                                                target.workspaceIdentity,
-                                                            }
-                                                          : {}),
-                                                      },
-                                                    });
+                                                    // 任务分收入口:打开专属分发对话框(纯 UI
+                                                    // 拆分 + 批量创建草稿任务),不走 agent 整理。
+                                                    setTaskDispatchTarget(target);
                                                   }
                                             }
                                           />
@@ -1988,6 +1980,15 @@ export const WorkspaceSidebar = memo(function WorkspaceSidebarComponent({
           ) : null}
         </div>
       </div>
+      {/* 任务分发对话框:纯 UI 拆分清单 → 批量创建草稿任务(见 TaskDispatchDialog)。 */}
+      <TaskDispatchDialog
+        open={taskDispatchTarget !== null}
+        target={taskDispatchTarget}
+        onOpenChange={(open) => {
+          if (!open) setTaskDispatchTarget(null);
+        }}
+        onCreateTask={(request) => onCreateTask(request)}
+      />
     </aside>
   );
 });

+ 24 - 0
packages/ui/src/WorkspaceSidebarItem.tsx

@@ -1043,6 +1043,30 @@ export const WorkspaceSidebarItem = memo(function WorkspaceSidebarItem({
                         </TaskRowActionButton>
                       </span>
                     ) : null}
+                    {shouldMountWorkspaceRowActions && onDispatchTasks ? (
+                      <span className="shrink-0">
+                        {/* 任务分发:项目行上的显式入口(与文件树按钮同组),
+                            打开专属分发对话框批量创建草稿任务。 */}
+                        <TaskRowActionButton
+                          className="text-foreground-subtle hover:text-foreground"
+                          label={intl.formatMessage({
+                            id: "workspaceSidebar.dispatchTasks",
+                          })}
+                          onClick={() => {
+                            onDispatchTasks({
+                              workspacePath: tab.workspacePath,
+                              ...(tab.workspaceIdentity
+                                ? { workspaceIdentity: tab.workspaceIdentity }
+                                : {}),
+                            });
+                          }}
+                          showTooltip
+                          disabledReason={readOnlyReason}
+                        >
+                          <ListTodo className="h-3.5 w-3.5" />
+                        </TaskRowActionButton>
+                      </span>
+                    ) : null}
                     {showRemoteConnectionErrorNotice ? (
                       remoteWorkspaceError ? (
                         <TooltipProvider>

+ 9 - 2
packages/ui/src/i18n/locales/en-US.ts

@@ -1854,8 +1854,15 @@ const enUS: Record<string, string> = {
   "workspaceSidebar.remove": "Remove",
   "workspaceSidebar.renameProject": "Rename project",
   "workspaceSidebar.dispatchTasks": "Dispatch tasks",
-  "workspaceSidebar.dispatchPlannerPrompt":
-    "Organize the batch of bugs/requests I describe into a list of independent tasks (deduplicate and merge overlapping items first). For each item give a short title and self-contained instructions, then use the DispatchTasks tool to create them under this project after I confirm the list. Always confirm the list with me before dispatching.",
+  "taskDispatch.title": "Dispatch tasks",
+  "taskDispatch.pastePlaceholder":
+    "Paste a batch of bugs / requests here.\nNumbered lists (1. 2. 3.), bullets (- * •) or blank-line paragraphs each become an independent task.",
+  "taskDispatch.parseHint": "Parsing happens locally with no model calls; results are editable.",
+  "taskDispatch.parse": "Parse list",
+  "taskDispatch.selectedCount": "{selected} of {total} selected",
+  "taskDispatch.reparse": "Paste again",
+  "taskDispatch.remove": "Remove this task",
+  "taskDispatch.createDrafts": "Create {count} task(s) (drafts)",
   "workspaceSidebar.renameProjectPlaceholder": "Custom project name (leave empty to reset)",
   "workspaceSidebar.renameProjectFailed": "Could not save project name",
   "chat.dashboard.turnsSteps": "{turns} turns · {steps} steps",

+ 9 - 2
packages/ui/src/i18n/locales/zh-CN.ts

@@ -1727,8 +1727,15 @@ const zhCN: Record<string, string> = {
   "workspaceSidebar.remove": "移除",
   "workspaceSidebar.renameProject": "项目重命名",
   "workspaceSidebar.dispatchTasks": "任务分发",
-  "workspaceSidebar.dispatchPlannerPrompt":
-    "请把我要处理的一批 bug/需求整理成独立任务清单(去重、合并重叠项),每项给出简短标题和自包含的处理说明,然后使用 DispatchTasks 工具在我确认后于本项目下创建这些任务。请先向我确认清单再分发。",
+  "taskDispatch.title": "任务分发",
+  "taskDispatch.pastePlaceholder":
+    "把一批 bug / 需求粘贴到这里。\n支持编号列表(1. 2. 3.)、项目符号(- * •)或空行分段,每项会拆成一个独立任务。",
+  "taskDispatch.parseHint": "解析在本地完成,不调用模型;拆分结果可编辑。",
+  "taskDispatch.parse": "解析清单",
+  "taskDispatch.selectedCount": "已选 {selected} / {total} 项",
+  "taskDispatch.reparse": "重新粘贴",
+  "taskDispatch.remove": "移除此任务",
+  "taskDispatch.createDrafts": "创建 {count} 个任务(草稿)",
   "workspaceSidebar.renameProjectPlaceholder": "自定义项目名称(留空恢复默认)",
   "workspaceSidebar.renameProjectFailed": "保存项目名称失败",
   "chat.dashboard.turnsSteps": "{turns} 轮 · {steps} 步",