Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(desktop): 顶部导航除新建外随任务列表一起滚动

Dash6becdb05bd5c
diff --git a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
index 5d90d57e7a..9022da3237 100644
--- a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
+++ b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
@@ -47,7 +47,7 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不
expect(sidebarUpperSource).not.toMatch(/[^t]setSelectedMachineId\(MACHINE_ALL\)/);
});
- it('SidebarTopNav 渲染 MachineSwitcherMenu 作列表末行(与新建 / 搜索同列表,固定不滚动)', () => {
+ it('SidebarTopNav 渲染 MachineSwitcherMenu 作列表末行(与新建 / 搜索同列表)', () => {
expect(topNavSource).toContain("from '@/features/cc-agent/sidebar/MachineSwitcherMenu'");
// 末行:出现在 SidebarInlineSearch 之后。
const searchIdx = topNavSource.indexOf('<SidebarInlineSearch');
@@ -56,6 +56,42 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不
expect(menuIdx).toBeGreaterThan(searchIdx);
});
+ // 2026-08-12 用户裁决(对齐 Codex):任务列表向上滚动时,除「新建」外的顶部导航行
+ // 一起滚走。实现为 SidebarTopNav 分段渲染 —— Shell 只画固定段,cc-agent 在自己的
+ // 列表滚动容器最上方画可滚动段;归属由 feature-context 的开关声明,Shell 不判路由。
+ it('顶部导航分两段:新建固定,其余行进任务列表滚动区', () => {
+ const featureContextSource = read('features', 'feature-context.tsx');
+ const sidebarShellSource = read('components', 'sidebar', 'Sidebar.tsx');
+
+ // 三段渲染契约。
+ expect(topNavSource).toContain(
+ "export type SidebarTopNavSection = 'all' | 'pinned' | 'scrollable'",
+ );
+ expect(topNavSource).toContain("const showPinned = section !== 'scrollable'");
+ expect(topNavSource).toContain("const showScrollable = section !== 'pinned'");
+
+ // Shell:接管时只画固定段,否则整块五行(插件页等无长列表的视图)。
+ expect(sidebarShellSource).toContain(
+ "<SidebarTopNav section={ownsTopNavScrollableRows ? 'pinned' : 'all'} />",
+ );
+ // Shell 仍不感知路由:归属只读 context 开关(架构不变量:Shell 不 import router)。
+ // 只查 import 语句——文件头注释里本就写着「刻意不 import useLocation」。
+ expect(sidebarShellSource).toContain('useOwnsTopNavScrollableRows()');
+ expect(sidebarShellSource).not.toMatch(/^import .*from 'react-router-dom'/m);
+
+ // cc-agent:展开态声明接管,并把可滚动段画进滚动容器;rail 态交回 Shell。
+ expect(sidebarUpperSource).toContain('useOwnTopNavScrollableRows(!isCollapsed)');
+ expect(sidebarUpperSource).toContain('<SidebarTopNav section="scrollable" />');
+ const scrollRefIdx = sidebarUpperSource.indexOf('ref={sidebarScrollRef}');
+ const scrollableRowsIdx = sidebarUpperSource.indexOf('<SidebarTopNav section="scrollable" />');
+ expect(scrollRefIdx).toBeGreaterThanOrEqual(0);
+ expect(scrollableRowsIdx).toBeGreaterThan(scrollRefIdx);
+
+ // 声明语义与 useRegisterSidebarUpper 一致:卸载不复位,避免切到 /settings 时闪变。
+ expect(featureContextSource).toContain('export function useOwnTopNavScrollableRows');
+ expect(featureContextSource).toContain('export function useOwnsTopNavScrollableRows');
+ });
+
it('连接中占位页不再自带 MachineSwitcherMenu(固定行已常驻,不会被困住)', () => {
const idx = sidebarUpperSource.indexOf('selectedMachineConnecting ?');
expect(idx).toBeGreaterThanOrEqual(0);
diff --git a/apps/desktop/src/renderer/components/sidebar/Sidebar.tsx b/apps/desktop/src/renderer/components/sidebar/Sidebar.tsx
index 3ed92d2e0e..1383463c24 100644
--- a/apps/desktop/src/renderer/components/sidebar/Sidebar.tsx
+++ b/apps/desktop/src/renderer/components/sidebar/Sidebar.tsx
@@ -22,7 +22,7 @@ import { cn } from '@/lib/utils';
import type { SidebarPeekDrawerProps, SidebarPeekState } from '@/hooks/useSidebarPeek';
import { useMacFullscreen } from '@/hooks/useMacFullscreen';
-import { useFeatureSidebarUpper } from '@/features/feature-context';
+import { useFeatureSidebarUpper, useOwnsTopNavScrollableRows } from '@/features/feature-context';
import { ConversationSearchProvider } from '@/features/cc-agent/sidebar/conversationSearchContext';
import { isSecondaryWindow } from '@/lib/secondaryWindow';
import { CHROME_ACTIONS_GEOMETRY } from '@/components/layout/chromeActionsGeometry';
@@ -81,6 +81,8 @@ export function Sidebar({
peekDrawerProps,
}: SidebarProps) {
const upperContent = useFeatureSidebarUpper();
+ // 当前 Feature 是否自行渲染顶部导航的可滚动段(见 feature-context)。
+ const ownsTopNavScrollableRows = useOwnsTopNavScrollableRows();
const { t } = useTranslation();
// 顶部 chrome 行的 no-drag 洞要对齐 ChromeActions 浮层按钮簇的落点:
// 按钮簇钉死左上角(mac 非全屏 78 让位红绿灯,其余 8),不随侧栏状态移动,
@@ -113,14 +115,14 @@ export function Sidebar({
// 拖拽中宽度直接跟手(useHorizontalResize 已把下限放宽到 railWidth)。
// peek 抽屉恒用展开宽 —— peek 的语义就是「预览完整展开列表」。
const visualWidth = isPeek
- ? width ?? 260
+ ? (width ?? 260)
: isCollapsed
? 0
: isDragging
- ? width ?? 260
+ ? (width ?? 260)
: isRail
? RAIL_WIDTH
- : width ?? 260;
+ : (width ?? 260);
// 内容层宽度:与 visualWidth 唯一的区别是**收起态不归零** —— 收起/展开动画期间
// 内容保持展开宽度被 aside 的 overflow-hidden 从右侧裁切,而不是跟随 aside 宽度
@@ -128,12 +130,12 @@ export function Sidebar({
// 对齐 Codex 的「文字淡出的同时侧栏收起」手感(2026-07 用户定稿;与右栏
// RightSidebar 的定宽内容层同一套路,规则 7)。
const contentWidth = isPeek
- ? width ?? 260
+ ? (width ?? 260)
: isDragging
- ? width ?? 260
+ ? (width ?? 260)
: isRail
? RAIL_WIDTH
- : width ?? 260;
+ : (width ?? 260);
return (
<aside
@@ -178,7 +180,7 @@ export function Sidebar({
)}
style={{ width: contentWidth }}
>
- {/* Top chrome 行: Sidebar 通顶后窗口左上角的空白 chrome 行(Codex 风格)。
+ {/* Top chrome 行: Sidebar 通顶后窗口左上角的空白 chrome 行(Codex 风格)。
- mac 非全屏:红绿灯悬浮在本行左侧。
- 折叠 + 菜单按钮**不在本行** —— 它们是 MainLayout 的 ChromeActions
浮层(浮在本行之上),钉死左上角红绿灯旁,不随侧栏状态移动。
@@ -187,56 +189,58 @@ export function Sidebar({
上可靠生效,浮层自身的 no-drag 不算数)。洞与按钮簇同坐标:
mac 非全屏 78(红绿灯右侧),mac 全屏 / Windows 8。
- 不画下边框 —— 顶行与列表区是一块连续表面(对齐 Codex)。 */}
- <div
- // 46px 与 ContentHeader / ChromeActions 行高一致(红绿灯心 y=23 同轴)。
- className="flex h-[46px] w-full shrink-0 items-center"
- style={{ WebkitAppRegion: 'drag' } as React.CSSProperties}
- >
<div
- aria-hidden
- // 60px = 折叠按钮 28 + gap 4 + 菜单 28(ChromeActions 簇宽)。
- className="h-full shrink-0"
- style={
- {
- width: CHROME_ACTIONS_GEOMETRY.clusterWidth,
- marginLeft: chromeClusterX,
- WebkitAppRegion: 'no-drag',
- } as React.CSSProperties
- }
- />
- </div>
+ // 46px 与 ContentHeader / ChromeActions 行高一致(红绿灯心 y=23 同轴)。
+ className="flex h-[46px] w-full shrink-0 items-center"
+ style={{ WebkitAppRegion: 'drag' } as React.CSSProperties}
+ >
+ <div
+ aria-hidden
+ // 60px = 折叠按钮 28 + gap 4 + 菜单 28(ChromeActions 簇宽)。
+ className="h-full shrink-0"
+ style={
+ {
+ width: CHROME_ACTIONS_GEOMETRY.clusterWidth,
+ marginLeft: chromeClusterX,
+ WebkitAppRegion: 'no-drag',
+ } as React.CSSProperties
+ }
+ />
+ </div>
- {/* ConversationSearchProvider:在顶部导航行(SidebarTopNav 的「搜索」行)与功能槽
+ {/* ConversationSearchProvider:在顶部导航行(SidebarTopNav 的「搜索」行)与功能槽
(CCAgentSidebarUpper 的结果 overlay)这两个兄弟子树的共同祖先处,只实例化一次
会话搜索状态,经 context 共享。外壳本身仍不感知搜索细节,只负责放置 Provider。 */}
- {shouldMountFeatureContent && (
- <ConversationSearchProvider>
- {/* 顶部常驻动作/导航列表(新建 / 自动任务 / Skill / 搜索)。
+ {shouldMountFeatureContent && (
+ <ConversationSearchProvider>
+ {/* 顶部常驻动作/导航列表(新建 / 自动任务 / Skill / 搜索)。
取代原 HorizontalTabbar:同级等权列表行,无单独项目 Tab。
rail(收窄)态放不下,隐藏——rail 自身承担入口;展开后回归。
完全隐藏态 w-0 自然裁掉。 */}
- {!isRail && <SidebarTopNav />}
+ {/* 任务列表页把「新建」以外的行搬进自己的列表滚动区(向上滚一起滚走,
+ 对齐 Codex);此时这里只渲染固定的「新建」。其它视图仍整块渲染五行。 */}
+ {!isRail && <SidebarTopNav section={ownsTopNavScrollableRows ? 'pinned' : 'all'} />}
- {/* Upper: feature-injected content slot.
+ {/* Upper: feature-injected content slot.
The current Feature Layout injects either an expanded or collapsed
sidebar tree through the FeatureSidebarSlotContext. Shell renders
whatever it's given. If no feature is active (e.g. /settings with
the intentionally empty SettingsSidebarUpper), this simply leaves
the upper area blank. */}
- <div className="flex flex-1 flex-col overflow-hidden">{upperContent}</div>
- </ConversationSearchProvider>
- )}
+ <div className="flex flex-1 flex-col overflow-hidden">{upperContent}</div>
+ </ConversationSearchProvider>
+ )}
- {/* Update banner: shown only when a verified update is ready
+ {/* Update banner: shown only when a verified update is ready
peek 抽屉视同展开(否则横幅在抽屉里消失,与「预览完整列表」语义相悖)。 */}
- <UpdateBanner
- isCollapsed={(isCollapsed && !isPeek) || isRail}
- onOpenVersionNotice={onOpenVersionNotice}
- />
+ <UpdateBanner
+ isCollapsed={(isCollapsed && !isPeek) || isRail}
+ onOpenVersionNotice={onOpenVersionNotice}
+ />
- {/* Bottom: User info (Shell-level, shared across all features)
+ {/* Bottom: User info (Shell-level, shared across all features)
isCollapsed 在这里表达"窄布局"(rail 居中头像);完全隐藏态 w-0 整体裁掉。 */}
- <UserInfoSection isCollapsed={isRail} onOpenUpdateNotice={onOpenUpdateNotice} />
+ <UserInfoSection isCollapsed={isRail} onOpenUpdateNotice={onOpenUpdateNotice} />
</div>
{/* Resize handle — expanded 和 rail 态都保留(rail 靠拖拽进出,F1 / F6)。
diff --git a/apps/desktop/src/renderer/components/sidebar/SidebarTopNav.tsx b/apps/desktop/src/renderer/components/sidebar/SidebarTopNav.tsx
index 68e6459fb0..cc3f15ee50 100644
--- a/apps/desktop/src/renderer/components/sidebar/SidebarTopNav.tsx
+++ b/apps/desktop/src/renderer/components/sidebar/SidebarTopNav.tsx
@@ -41,7 +41,22 @@ const ROW_CLASS =
const ROW_ACTIVE_CLASS =
'bg-sidebar-item-active font-medium text-sidebar-item-active-foreground shadow-[inset_0_0_0_1px_var(--sidebar-item-active-border)] hover:bg-sidebar-item-active';
-export function SidebarTopNav(): React.ReactElement {
+/**
+ * 渲染范围。任务列表页把「新建」以外的行搬进列表滚动区(向上滚时一起滚走,
+ * 对齐 Codex;2026-08-12 用户裁决),因此本组件要能分两段渲染:
+ * - 'all'(默认):五行全渲染。非 cc-agent 视图(插件页 / Skill 页等)沿用,
+ * 那些页的侧栏没有长列表,不存在滚动需求。
+ * - 'pinned':只渲染「新建」——Shell 顶部固定段。
+ * - 'scrollable':渲染其余行(自动任务 / 插件 / 搜索 / 远程机器),由 cc-agent
+ * 的侧栏滚动容器在列表最上方绘制。
+ */
+export type SidebarTopNavSection = 'all' | 'pinned' | 'scrollable';
+
+export function SidebarTopNav({
+ section = 'all',
+}: {
+ section?: SidebarTopNavSection;
+} = {}): React.ReactElement {
const { t } = useTranslation();
const navigate = useNavigate();
const { activeKey, navigateToView } = useActiveMainView();
@@ -64,71 +79,94 @@ export function SidebarTopNav(): React.ReactElement {
// 用户在 plugins / 设置等视图输入搜索时,先切回 cc-agent 视图,结果才有处显示(同视图为 no-op)。
const ensureConversationView = useCallback(() => navigateToView('cc-agent'), [navigateToView]);
+ const showPinned = section !== 'scrollable';
+ const showScrollable = section !== 'pinned';
+
return (
// pt-1(原 2.5):顶行 chrome 收窄到 46px 后,列表整体上提贴近顶行(对齐 Codex)。
- <div className="flex flex-col gap-0.5 pt-1 pr-3 pb-2.5 pl-3">
- {/* 1. 新建 —— 图标 15/1.8 + meta 灰:与项目行的文件夹图标同规格同色
- (2026-07 用户定稿,对齐 Codex;文字仍用 foreground)。 */}
- <button onClick={handleNew} className={ROW_CLASS} aria-label={t('ccAgent.layout.new')}>
- <CirclePlus
- size={15}
- strokeWidth={1.8}
- className="shrink-0 text-[var(--sidebar-nav-text)]"
- />
- <span className="leading-none">{t('ccAgent.layout.new')}</span>
- </button>
+ // 分段渲染时(section≠'all')两段各自成块,由调用方分别放进固定区 / 滚动区;
+ // padding 保持同一套,两段拼起来的视觉与整块渲染一致。pinned 段不带 pb,
+ // 让滚动段紧随其后(行距仍由滚动段容器的 gap 承担)。
+ <div
+ className={cn(
+ 'flex flex-col gap-0.5 pt-1 pr-3 pl-3',
+ section === 'pinned' ? 'pb-0.5' : 'pb-2.5',
+ // 滚动段接在固定段下方,不再需要顶部 chrome 让位。
+ section === 'scrollable' && 'pt-0',
+ )}
+ >
+ {showPinned && (
+ /* 1. 新建 —— 图标 15/1.8 + meta 灰:与项目行的文件夹图标同规格同色
+ (2026-07 用户定稿,对齐 Codex;文字仍用 foreground)。 */
+ <button onClick={handleNew} className={ROW_CLASS} aria-label={t('ccAgent.layout.new')}>
+ <CirclePlus
+ size={15}
+ strokeWidth={1.8}
+ className="shrink-0 text-[var(--sidebar-nav-text)]"
+ />
+ <span className="leading-none">{t('ccAgent.layout.new')}</span>
+ </button>
+ )}
- {/* 2. 自动任务 —— 仅作导航入口,不再在此提示自动化任务的运行状态(dot 已移除,
+ {showScrollable && (
+ <>
+ {/* 2. 自动任务 —— 仅作导航入口,不再在此提示自动化任务的运行状态(dot 已移除,
未读 / 运行状态由下方各 schedule 组头承载)。 */}
- <button
- onClick={() => navigate('/cc-agent/scheduled')}
- className={cn(ROW_CLASS, onScheduleMatch && ROW_ACTIVE_CLASS)}
- aria-label={t('ccAgent.layout.automations')}
- aria-current={onScheduleMatch ? 'page' : undefined}
- >
- <Timer
- size={15}
- strokeWidth={1.8}
- className={cn(
- 'shrink-0',
- // 选中反相胶囊上图标跟随 active 前景(图标自带显式色,行级 text 覆盖不到它)。
- onScheduleMatch ? 'text-sidebar-item-active-foreground' : 'text-[var(--sidebar-nav-text)]',
- )}
- />
- <span className="leading-none">{t('ccAgent.layout.automations')}</span>
- </button>
+ <button
+ onClick={() => navigate('/cc-agent/scheduled')}
+ className={cn(ROW_CLASS, onScheduleMatch && ROW_ACTIVE_CLASS)}
+ aria-label={t('ccAgent.layout.automations')}
+ aria-current={onScheduleMatch ? 'page' : undefined}
+ >
+ <Timer
+ size={15}
+ strokeWidth={1.8}
+ className={cn(
+ 'shrink-0',
+ // 选中反相胶囊上图标跟随 active 前景(图标自带显式色,行级 text 覆盖不到它)。
+ onScheduleMatch
+ ? 'text-sidebar-item-active-foreground'
+ : 'text-[var(--sidebar-nav-text)]',
+ )}
+ />
+ <span className="leading-none">{t('ccAgent.layout.automations')}</span>
+ </button>
- {/* 3. Plugins —— Plugin / Skill 在页面顶部 Tab 内切换 */}
- <button
- onClick={() => navigateToView('plugins')}
- className={cn(ROW_CLASS, activeKey === 'plugins' && ROW_ACTIVE_CLASS)}
- aria-label={t('sidebar.tabs.plugins')}
- aria-current={activeKey === 'plugins' ? 'page' : undefined}
- >
- <Plug
- size={15}
- strokeWidth={1.8}
- className={cn(
- 'shrink-0',
- // 同上:选中反相胶囊上图标跟随 active 前景。
- activeKey === 'plugins' ? 'text-sidebar-item-active-foreground' : 'text-[var(--sidebar-nav-text)]',
- )}
- />
- <span className="leading-none">{t('sidebar.tabs.plugins')}</span>
- {hasGhostUnread && <AttentionDot size={6} className="ml-auto mr-0.5" />}
- </button>
+ {/* 3. Plugins —— Plugin / Skill 在页面顶部 Tab 内切换 */}
+ <button
+ onClick={() => navigateToView('plugins')}
+ className={cn(ROW_CLASS, activeKey === 'plugins' && ROW_ACTIVE_CLASS)}
+ aria-label={t('sidebar.tabs.plugins')}
+ aria-current={activeKey === 'plugins' ? 'page' : undefined}
+ >
+ <Plug
+ size={15}
+ strokeWidth={1.8}
+ className={cn(
+ 'shrink-0',
+ // 同上:选中反相胶囊上图标跟随 active 前景。
+ activeKey === 'plugins'
+ ? 'text-sidebar-item-active-foreground'
+ : 'text-[var(--sidebar-nav-text)]',
+ )}
+ />
+ <span className="leading-none">{t('sidebar.tabs.plugins')}</span>
+ {hasGhostUnread && <AttentionDot size={6} className="ml-auto mr-0.5" />}
+ </button>
- {/* 4. 搜索 —— 静息态与上面三行同款;hover / 聚焦就地展开成搜索框 */}
- <SidebarInlineSearch
- search={search}
- allKnownProjects={allKnownProjects}
- openSignal={openSignal}
- onSearchActive={ensureConversationView}
- />
+ {/* 4. 搜索 —— 静息态与上面三行同款;hover / 聚焦就地展开成搜索框 */}
+ <SidebarInlineSearch
+ search={search}
+ allKnownProjects={allKnownProjects}
+ openSignal={openSignal}
+ onSearchActive={ensureConversationView}
+ />
- {/* 5. 远程机器 —— 同款行样式的文字下拉(过滤下方会话列表的机器范围);
+ {/* 5. 远程机器 —— 同款行样式的文字下拉(过滤下方会话列表的机器范围);
无相关远程机器时组件自身 return null,不占行。 */}
- <MachineSwitcherMenu />
+ <MachineSwitcherMenu />
+ </>
+ )}
</div>
);
}
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index 3ba2568fa0..0a0ca997c6 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@ -61,7 +61,8 @@ import {
SWITCH_SESSION_SHORTCUT_IDS,
} from '../../../shared/appShortcuts';
import { setSessionOrdinalBadges } from './sidebar/sessionOrdinalBadges';
-import { useSidebarCollapsedState } from '../feature-context';
+import { useOwnTopNavScrollableRows, useSidebarCollapsedState } from '../feature-context';
+import { SidebarTopNav } from '@/components/sidebar/SidebarTopNav';
import { stripTrailingPathSeparators } from '../../../shared/pathText';
import { useRefreshWorktrees } from '@/contexts/WorktreeContext';
import {
@@ -381,6 +382,10 @@ export function CCAgentSidebarUpper() {
const { t } = useTranslation();
const localPlatform = window.electronAPI.platform;
const isCollapsed = useSidebarCollapsedState();
+ // 展开态由本 Feature 在自己的列表滚动区里渲染顶部导航的可滚动段(自动任务 /
+ // 插件 / 搜索 / 远程机器),shell 顶部只留固定的「新建」——列表上滚时这些行一起
+ // 滚走(2026-08-12 用户裁决,对齐 Codex)。rail 态没有该滚动区,交回 shell 整块渲染。
+ useOwnTopNavScrollableRows(!isCollapsed);
// 错误红点的派生真源:拉取存在未处理告警(中断 ∪ 未 dismissed 错误尾行)的会话
// 并在收敛触发点重算 —— 横幅不被处置,红点就不消失。
usePendingAlertAttention();
@@ -3018,15 +3023,18 @@ function ExpandedView({
</div>
)}
- {/* 侧栏内容区:单一滚动容器(置顶 + 项目 + 对话一起滚动)。外层 relative 承载搜索结果
- overlay。远程机器切换入口是 shell SidebarTopNav 的末行(与新建 / 搜索同列表),
- 固定在本区上方、不随列表滚动。 */}
+ {/* 侧栏内容区:单一滚动容器(顶部导航的可滚动段 + 置顶 + 项目 + 对话一起滚动)。
+ 外层 relative 承载搜索结果 overlay。「新建」仍固定在 shell 顶部;自动任务 /
+ 插件 / 搜索 / 远程机器四行随列表滚走(2026-08-12 用户裁决,对齐 Codex)。 */}
<div className="relative flex min-h-0 flex-1 flex-col">
<div
ref={sidebarScrollRef}
- className="flex flex-col gap-2 pt-2 pb-4 overflow-y-auto flex-1"
+ className="flex flex-col gap-2 pt-0 pb-4 overflow-y-auto flex-1"
style={{ scrollbarGutter: 'stable' }}
>
+ {/* 顶部导航可滚动段:置于列表最上方,一起滚动。本组件即展开态视图
+ (rail 走 CollapsedView 自己的图标入口),无需再判折叠。 */}
+ <SidebarTopNav section="scrollable" />
{remoteDeviceDirectoryStatus === 'error' && !hasVisibleSidebarContent ? (
<RemoteSidebarLoadNotice
kind="devices"
diff --git a/apps/desktop/src/renderer/features/feature-context.tsx b/apps/desktop/src/renderer/features/feature-context.tsx
index 412a624a84..05697af7ca 100644
--- a/apps/desktop/src/renderer/features/feature-context.tsx
+++ b/apps/desktop/src/renderer/features/feature-context.tsx
@@ -53,6 +53,15 @@ interface FeatureSidebarSlotContextValue {
setSidebarEnabled: Dispatch<SetStateAction<boolean>>;
/** 当前 Feature 是否需要 Sidebar */
sidebarEnabled: boolean;
+ /**
+ * 当前 Feature 是否自行在其滚动区里渲染顶部导航的「可滚动段」(自动任务 / 插件 /
+ * 搜索 / 远程机器)。true 时 Shell 顶部只保留固定的「新建」行,其余交给 Feature
+ * ——任务列表页据此让这些行随列表一起滚走(2026-08-12 用户裁决,对齐 Codex)。
+ * 默认 false:没有长列表的视图(插件页等)仍由 Shell 整块渲染五行。
+ */
+ ownsTopNavScrollableRows: boolean;
+ /** 内部 setter,Feature 经 useOwnTopNavScrollableRows 声明。 */
+ setOwnsTopNavScrollableRows: Dispatch<SetStateAction<boolean>>;
}
const FeatureSidebarSlotContext = createContext<FeatureSidebarSlotContextValue | null>(null);
@@ -73,6 +82,7 @@ export function FeatureSidebarSlotProvider({
const [upperContent, setUpperContent] = useState<ReactNode>(null);
const [headerContent, setHeaderContent] = useState<ReactNode>(null);
const [sidebarEnabled, setSidebarEnabled] = useState(true);
+ const [ownsTopNavScrollableRows, setOwnsTopNavScrollableRows] = useState(false);
const value = useMemo<FeatureSidebarSlotContextValue>(
() => ({
@@ -83,8 +93,10 @@ export function FeatureSidebarSlotProvider({
isCollapsed,
sidebarEnabled,
setSidebarEnabled,
+ ownsTopNavScrollableRows,
+ setOwnsTopNavScrollableRows,
}),
- [upperContent, headerContent, isCollapsed, sidebarEnabled],
+ [upperContent, headerContent, isCollapsed, sidebarEnabled, ownsTopNavScrollableRows],
);
return (
@@ -101,9 +113,7 @@ export function FeatureSidebarSlotProvider({
export function useFeatureSidebarUpper(): ReactNode {
const ctx = useContext(FeatureSidebarSlotContext);
if (!ctx) {
- throw new Error(
- 'useFeatureSidebarUpper must be used inside <FeatureSidebarSlotProvider>',
- );
+ throw new Error('useFeatureSidebarUpper must be used inside <FeatureSidebarSlotProvider>');
}
return ctx.upperContent;
}
@@ -114,9 +124,7 @@ export function useFeatureSidebarUpper(): ReactNode {
export function useSidebarCollapsedState(): boolean {
const ctx = useContext(FeatureSidebarSlotContext);
if (!ctx) {
- throw new Error(
- 'useSidebarCollapsedState must be used inside <FeatureSidebarSlotProvider>',
- );
+ throw new Error('useSidebarCollapsedState must be used inside <FeatureSidebarSlotProvider>');
}
return ctx.isCollapsed;
}
@@ -127,9 +135,7 @@ export function useSidebarCollapsedState(): boolean {
export function useFeatureSidebarEnabled(): boolean {
const ctx = useContext(FeatureSidebarSlotContext);
if (!ctx) {
- throw new Error(
- 'useFeatureSidebarEnabled must be used inside <FeatureSidebarSlotProvider>',
- );
+ throw new Error('useFeatureSidebarEnabled must be used inside <FeatureSidebarSlotProvider>');
}
return ctx.sidebarEnabled;
}
@@ -144,9 +150,7 @@ export function useFeatureSidebarEnabled(): boolean {
export function useRegisterSidebarUpper(node: ReactNode): void {
const ctx = useContext(FeatureSidebarSlotContext);
if (!ctx) {
- throw new Error(
- 'useRegisterSidebarUpper must be used inside <FeatureSidebarSlotProvider>',
- );
+ throw new Error('useRegisterSidebarUpper must be used inside <FeatureSidebarSlotProvider>');
}
const { setUpperContent } = ctx;
@@ -158,6 +162,33 @@ export function useRegisterSidebarUpper(node: ReactNode): void {
}, [node, setUpperContent]);
}
+/**
+ * Feature 声明「顶部导航的可滚动段由我在自己的滚动区里渲染」。
+ * 与 useRegisterSidebarUpper 同款语义:卸载时**不**复位——沿用「保持最后一个
+ * Feature 的声明」,避免导航到 /settings 等非 Feature 路由时顶部导航闪一下变形。
+ * 下一个 Feature 挂载时自然覆盖(不接管的 Feature 传 false)。
+ */
+export function useOwnTopNavScrollableRows(owns: boolean): void {
+ const ctx = useContext(FeatureSidebarSlotContext);
+ if (!ctx) {
+ throw new Error('useOwnTopNavScrollableRows must be used inside <FeatureSidebarSlotProvider>');
+ }
+ const { setOwnsTopNavScrollableRows } = ctx;
+
+ useLayoutEffect(() => {
+ setOwnsTopNavScrollableRows(owns);
+ }, [owns, setOwnsTopNavScrollableRows]);
+}
+
+/** Sidebar Shell 读取:顶部导航是否只渲染固定段(可滚动段已被 Feature 接管)。 */
+export function useOwnsTopNavScrollableRows(): boolean {
+ const ctx = useContext(FeatureSidebarSlotContext);
+ if (!ctx) {
+ throw new Error('useOwnsTopNavScrollableRows must be used inside <FeatureSidebarSlotProvider>');
+ }
+ return ctx.ownsTopNavScrollableRows;
+}
+
/**
* ContentHeader Shell 读取当前要渲染的中部内容。
* 只读,不包含 setter。
@@ -165,9 +196,7 @@ export function useRegisterSidebarUpper(node: ReactNode): void {
export function useFeatureContentHeader(): ReactNode {
const ctx = useContext(FeatureSidebarSlotContext);
if (!ctx) {
- throw new Error(
- 'useFeatureContentHeader must be used inside <FeatureSidebarSlotProvider>',
- );
+ throw new Error('useFeatureContentHeader must be used inside <FeatureSidebarSlotProvider>');
}
return ctx.headerContent;
}
@@ -184,9 +213,7 @@ export function useFeatureContentHeader(): ReactNode {
export function useRegisterContentHeader(node: ReactNode): void {
const ctx = useContext(FeatureSidebarSlotContext);
if (!ctx) {
- throw new Error(
- 'useRegisterContentHeader must be used inside <FeatureSidebarSlotProvider>',
- );
+ throw new Error('useRegisterContentHeader must be used inside <FeatureSidebarSlotProvider>');
}
const { setHeaderContent } = ctx;
@@ -206,9 +233,7 @@ export function useRegisterContentHeader(node: ReactNode): void {
export function useSetSidebarEnabled(enabled: boolean): void {
const ctx = useContext(FeatureSidebarSlotContext);
if (!ctx) {
- throw new Error(
- 'useSetSidebarEnabled must be used inside <FeatureSidebarSlotProvider>',
- );
+ throw new Error('useSetSidebarEnabled must be used inside <FeatureSidebarSlotProvider>');
}
const { setSidebarEnabled } = ctx;
diff --git a/docs/product-rules/sidebar-redesign-plan.md b/docs/product-rules/sidebar-redesign-plan.md
index f904ef7148..f19634d561 100644
--- a/docs/product-rules/sidebar-redesign-plan.md
+++ b/docs/product-rules/sidebar-redesign-plan.md
@@ -20,13 +20,21 @@
## 2. 信息架构
```
-[顶部导航] 新建 / 自动任务 / 插件 / 搜索 / 设备下拉(仅远程连接时出现)
+[新建] 固定不滚动
+─────────── 以下随列表一起滚动 ───────────
+[顶部导航] 自动任务 / 插件 / 搜索 / 设备下拉(仅远程连接时出现)
[置顶区] 可折叠;会话与项目混排置顶,共享一份拖拽顺序(现状语义不变)
[全部任务] 单一主列表(混排模型,见 §3)
```
「按日期分组」模式删除(`DateGroupedSessionsSection` 及 `groupBy === 'date'` 分支)。
+**只有「新建」固定**(2026-08-12 用户裁决,对齐 Codex):列表向上滚动时,顶部导航
+其余四行跟着滚走,把纵向空间让给任务列表。实现上 `SidebarTopNav` 支持分段渲染
+(`pinned` / `scrollable`),Shell 画固定段、任务列表页在自己的滚动容器最上方画可滚动段;
+归属由功能槽经 `useOwnTopNavScrollableRows` 声明,**Shell 不判路由**(维持"外壳不感知
+路由"的架构不变量)。没有长列表的视图(插件页等)与 rail 态仍由 Shell 整块渲染五行。
+
## 3. 整理侧边栏菜单(定稿结构)
入口:「全部任务」段头 hover 出现的整理按钮,**点击展开**(2026-08-12 用户裁决,