Просмотр исходного кода

feat(ui): 任务分发模块 M2 接线——主视图路由与侧栏入口

- WorkspaceMainView 新增 "task-dispatch" 视图,chatContent 分支复用
  AutomationsMainBreadcrumbFrame + ScopedErrorBoundary 模式渲染 TaskDispatchModule
- 侧栏在「定时任务」与「插件商店」之间新增任务分发入口按钮,
  皮肤图标回退 ListTodo,active 态与其它主视图入口一致
- TaskDispatchModule 项目选项改为内部从 tabStore 派生(与侧栏任务区同源,
  复用 useLocalWorkspaceScopes 过滤本地可用 workspace),身份 key 走
  getWorkspaceKey,避免第二份列表状态与 prop 穿透
- 同步更新三处全枚举判断:主视图 header 显隐、终端面板显隐、
  手机远控回落聊天页(远控不承载任务分发)

验证:pnpm typecheck 通过;pnpm lint 63 警告 0 错误(与基线一致)。
wubinggen 1 месяц назад
Родитель
Сommit
b1a96abbec

+ 28 - 0
packages/ui/src/WorkspaceSidebar.tsx

@@ -15,6 +15,7 @@ import {
   Archive,
   Blocks,
   CalendarClock,
+  ListTodo,
   Clock3,
   Cloud,
   Folder,
@@ -268,8 +269,10 @@ export const WorkspaceSidebar = memo(function WorkspaceSidebarComponent({
   onOpenCommandCenter,
   onOpenAutomations,
   onOpenPluginStore,
+  onOpenTaskDispatch,
   automationsActive = false,
   pluginStoreActive = false,
+  taskDispatchActive = false,
   onFileTreeOpenChange,
   onWebRemoteTaskOpen,
   onWebRemoteTaskSwitchingChange,
@@ -324,8 +327,10 @@ export const WorkspaceSidebar = memo(function WorkspaceSidebarComponent({
   onOpenCommandCenter: () => void;
   onOpenAutomations?: () => void;
   onOpenPluginStore?: () => void;
+  onOpenTaskDispatch?: () => void;
   automationsActive?: boolean;
   pluginStoreActive?: boolean;
+  taskDispatchActive?: boolean;
   onFileTreeOpenChange?: (open: boolean) => void;
   onWebRemoteTaskOpen?: (options: { crossWorkspace: boolean }) => void;
   onWebRemoteTaskSwitchingChange?: (switching: boolean) => void;
@@ -333,6 +338,8 @@ export const WorkspaceSidebar = memo(function WorkspaceSidebarComponent({
   const { intl, localePreference, setLocalePreference } = useZCodeIntl();
   const SearchIcon = useSkinActionIcon("search", Search);
   const AutomationsIcon = useSkinActionIcon("automations", CalendarClock);
+  // 任务分发独立模块入口:皮肤未提供专属图标时回退 ListTodo。
+  const TaskDispatchIcon = useSkinActionIcon("task-dispatch", ListTodo);
   const PluginStoreIcon = useSkinActionIcon("plugin-store", Blocks);
   const handleTaskRowSelect = useCallback(
     (
@@ -879,6 +886,9 @@ export const WorkspaceSidebar = memo(function WorkspaceSidebarComponent({
   const handleOpenAutomationsMain = useCallback(() => {
     onOpenAutomations?.();
   }, [onOpenAutomations]);
+  const handleOpenTaskDispatchMain = useCallback(() => {
+    onOpenTaskDispatch?.();
+  }, [onOpenTaskDispatch]);
   const handleOpenCodingPlanUpgrade = useCallback(
     (
       providerId: string,
@@ -1565,6 +1575,24 @@ export const WorkspaceSidebar = memo(function WorkspaceSidebarComponent({
                 {intl.formatMessage({ id: "workspace.openScheduledSettings" })}
               </Button>
             ) : null}
+            {!isWebRemoteControlSidebar ? (
+              <Button
+                variant="ghost"
+                onClick={handleOpenTaskDispatchMain}
+                data-icon="inline-start"
+                data-skin-action="task-dispatch"
+                data-testid="task-dispatch-sidebar-open"
+                size="lg"
+                aria-pressed={taskDispatchActive}
+                className={cn(
+                  "w-full justify-start gap-2 text-foreground hover:bg-surface-hover hover:text-foreground",
+                  taskDispatchActive && "bg-selected text-foreground",
+                )}
+              >
+                <TaskDispatchIcon className="size-4" />
+                {intl.formatMessage({ id: "taskDispatch.module.title" })}
+              </Button>
+            ) : null}
             <Button
               variant="ghost"
               onClick={handleOpenPluginStoreMain}

+ 38 - 2
packages/ui/src/app-shell/WorkspaceShellLayout.tsx

@@ -52,6 +52,7 @@ import type {
   SavedWorkflowsOpenRunParams,
 } from "@/settings/saved-workflows/SavedWorkflowsSection.js";
 import { AutomationsMainBreadcrumbFrame } from "@/settings/AutomationsMainBreadcrumbFrame.js";
+import { TaskDispatchModule } from "@/task-dispatch/TaskDispatchModule.js";
 import { PluginStorePage } from "@/settings/PluginStorePage.js";
 import { TaskFindDialog } from "@/quickpick/TaskFindDialog.js";
 import { WebRemoteControlMobileShell } from "@/WebRemoteControlMobileShell.js";
@@ -1272,6 +1273,9 @@ export const WorkspaceShellLayout = memo(
     const showChatMainView = useCallback(() => {
       onWorkspaceMainViewChange("chat");
     }, [onWorkspaceMainViewChange]);
+    const handleOpenTaskDispatchMain = useCallback(() => {
+      onWorkspaceMainViewChange("task-dispatch");
+    }, [onWorkspaceMainViewChange]);
     const primaryNavigationBack =
       workspaceMainView === "plugin-store"
         ? handleManageInstalledPlugins
@@ -1282,10 +1286,11 @@ export const WorkspaceShellLayout = memo(
       if (
         isWebRemoteControlShell &&
         (workspaceMainView === "automations" ||
+          workspaceMainView === "task-dispatch" ||
           workspaceMainView === "plugin-store")
       ) {
         // 修复原因:手机远控复用桌面 shell 时可能保留上一次主视图状态;
-        // 远控不承载 Automations,必须立即回落到 continuous/replayable 边界之外的聊天页。
+        // 远控不承载 Automations/任务分发,必须立即回落到 continuous/replayable 边界之外的聊天页。
         onWorkspaceMainViewChange("chat");
       }
     }, [isWebRemoteControlShell, onWorkspaceMainViewChange, workspaceMainView]);
@@ -2039,6 +2044,7 @@ export const WorkspaceShellLayout = memo(
     // 手机远控无 active task 时仍不渲染桌面 chrome,继续遵守 replayable overlay 边界。
     const shouldRenderMainViewHeader =
       workspaceMainView !== "automations" &&
+      workspaceMainView !== "task-dispatch" &&
       workspaceMainView !== "plugin-store";
     const shouldRenderWorkspaceHeader =
       shouldRenderMainViewHeader && (activeTaskId !== null || isDesktop);
@@ -2216,6 +2222,32 @@ export const WorkspaceShellLayout = memo(
                     </div>
                   </AutomationsMainBreadcrumbFrame>
                 </main>
+              ) : workspaceMainView === "task-dispatch" &&
+                !isWebRemoteControlShell ? (
+                <main className="flex h-full min-h-0 flex-1 flex-col bg-background">
+                  <AutomationsMainBreadcrumbFrame
+                    isDesktop={Boolean(isDesktop)}
+                    sectionLabel={intl.formatMessage({
+                      id: "taskDispatch.module.title",
+                    })}
+                    ariaLabel={intl.formatMessage({
+                      id: "taskDispatch.module.title",
+                    })}
+                  >
+                    <div className="min-h-0 flex-1 overflow-y-auto [scrollbar-gutter:stable]">
+                      <ScopedErrorBoundary
+                        scope="task-dispatch-main"
+                        resetKeys={workspaceOnlyResetKeys}
+                        variant="panel"
+                        className="min-h-full"
+                      >
+                        <div className="mx-auto flex h-full min-h-0 w-full max-w-5xl flex-col px-4 py-4 md:px-6 md:py-6">
+                          <TaskDispatchModule />
+                        </div>
+                      </ScopedErrorBoundary>
+                    </div>
+                  </AutomationsMainBreadcrumbFrame>
+                </main>
               ) : workspaceMainView === "plugin-store" &&
                 !isWebRemoteControlShell ? (
                 <main className="flex h-full min-h-0 flex-1 flex-col bg-background">
@@ -2459,6 +2491,8 @@ export const WorkspaceShellLayout = memo(
                     onOpenCommandCenter={handleOpenCommandCenter}
                     onOpenAutomations={handleOpenAutomations}
                     automationsActive={workspaceMainView === "automations"}
+                    onOpenTaskDispatch={handleOpenTaskDispatchMain}
+                    taskDispatchActive={workspaceMainView === "task-dispatch"}
                     onOpenPluginStore={handleOpenPluginStore}
                     pluginStoreActive={workspaceMainView === "plugin-store"}
                     onFileTreeOpenChange={setIsSidebarFileTreeOpen}
@@ -2856,7 +2890,9 @@ export const WorkspaceShellLayout = memo(
                   </section>
                     </ResizablePanel>
                     {isWebRemoteControlShell ||
-                      (workspaceMainView !== "automations" && workspaceMainView !== "plugin-store") ? (
+                      (workspaceMainView !== "automations" &&
+                        workspaceMainView !== "task-dispatch" &&
+                        workspaceMainView !== "plugin-store") ? (
                           <AnimatedTerminalPanel
                             frameClassName={cn(
                               isSidePaneVisible ? "rounded-[var(--workspace-panel-radius)] border border-border" : resolveWorkspaceShellWindowChromeClass({

+ 5 - 1
packages/ui/src/app-shell/types.ts

@@ -125,7 +125,11 @@ export interface GitChangeSummary {
   removed: number;
 }
 
-export type WorkspaceMainView = "chat" | "automations" | "plugin-store";
+export type WorkspaceMainView =
+  | "chat"
+  | "automations"
+  | "task-dispatch"
+  | "plugin-store";
 
 export interface WorkspaceShellLayoutProps extends Omit<AppProps, "baseFeedbackService"> {
   workspaceReadOnlyReason?: string;

+ 37 - 6
packages/ui/src/task-dispatch/TaskDispatchModule.tsx

@@ -17,6 +17,10 @@ import {
 } from "@/components/ui/select.js";
 import { useZCodeIntl } from "@/i18n/IntlProvider.js";
 import { cn } from "@/components/lib/utils.js";
+import { useTabStore } from "@/store/TabStoreProvider.js";
+import { isWorkspaceTab } from "@/store/tabStore.js";
+import { useLocalWorkspaceScopes } from "@/hooks/useLocalWorkspaceScopes.js";
+import { getWorkspaceKey } from "@/lib/workspaceKey.js";
 
 /** 模块内可选的项目目标(本地 + 远程 workspace)。 */
 export interface TaskDispatchWorkspaceOption {
@@ -26,19 +30,46 @@ export interface TaskDispatchWorkspaceOption {
   workspaceIdentity?: string;
 }
 
+/** 从 tabStore 派生项目 workspace 选项;与侧栏任务区同一数据源,避免第二份列表状态。 */
+function useTaskDispatchWorkspaceOptions(): TaskDispatchWorkspaceOption[] {
+  const tabs = useTabStore((state) => state.tabs);
+  const workspaceTabs = useMemo(() => tabs.filter(isWorkspaceTab), [tabs]);
+  const localWorkspaceTabs = useLocalWorkspaceScopes({ workspaceTabs });
+  return useMemo(
+    () =>
+      localWorkspaceTabs
+        // 只保留真实项目 tab;conversation backing path 不参与任务分发。
+        .filter((tab) => tab.workspacePurpose !== "conversation")
+        .map((tab) => ({
+          // 身份 key 统一走 getWorkspaceKey(workspaceIdentity 优先,trim 后回退路径)。
+          key: getWorkspaceKey(tab.workspacePath, tab.workspaceIdentity),
+          label: tab.label || workspaceBasename(tab.workspacePath),
+          workspacePath: tab.workspacePath,
+          workspaceIdentity: tab.workspaceIdentity,
+        })),
+    [localWorkspaceTabs],
+  );
+}
+
+function workspaceBasename(path: string): string {
+  return path.replace(/\\/g, "/").split("/").filter(Boolean).pop() ?? path;
+}
+
 export function TaskDispatchModule({
   workspaceOptions,
 }: {
-  /** 由宿主注入可选项目列表(侧栏 workspace tabs 派生)。 */
-  workspaceOptions: TaskDispatchWorkspaceOption[];
+  /** 可选:由宿主注入覆盖;缺省时从 tabStore 的项目 workspace 派生。 */
+  workspaceOptions?: TaskDispatchWorkspaceOption[];
 }) {
   const { intl } = useZCodeIntl();
+  const derivedOptions = useTaskDispatchWorkspaceOptions();
+  const options = workspaceOptions ?? derivedOptions;
   const [selectedKey, setSelectedKey] = useState<string | null>(
-    workspaceOptions[0]?.key ?? null,
+    options[0]?.key ?? null,
   );
   const selected = useMemo(
-    () => workspaceOptions.find((option) => option.key === selectedKey) ?? null,
-    [workspaceOptions, selectedKey],
+    () => options.find((option) => option.key === selectedKey) ?? null,
+    [options, selectedKey],
   );
 
   return (
@@ -68,7 +99,7 @@ export function TaskDispatchModule({
             />
           </SelectTrigger>
           <SelectContent>
-            {workspaceOptions.map((option) => (
+            {options.map((option) => (
               <SelectItem key={option.key} value={option.key}>
                 {option.label}
               </SelectItem>