diff --git a/.agents/notes/implemented/feature/2026-11-05-session-panel.i18n.yaml b/.agents/notes/implemented/feature/2026-11-05-session-panel.i18n.yaml index b31971c7e3..739ea8715b 100644 --- a/.agents/notes/implemented/feature/2026-11-05-session-panel.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-11-05-session-panel.i18n.yaml @@ -15,8 +15,8 @@ en: 8a97ac8ac0b40d0c zh: d42fe9c23b9dcd79 /agent-note-session-panel-in-the-chat-view-s-end-gutter/decision/sections-are-registrations-the-panel-draws-titles: - en: d93135868e42f9a0 - zh: b3336f9be64ef789 + en: d6f85e07351ad90e + zh: f883a99c8ca98522 /agent-note-session-panel-in-the-chat-view-s-end-gutter/decision/the-turn-rail-sits-at-the-start-edge: en: 08e720a4ea75d4d6 zh: 5e2e5b8452f67d36 diff --git a/.agents/notes/implemented/feature/2026-11-05-session-panel.md b/.agents/notes/implemented/feature/2026-11-05-session-panel.md index 751fb73257..6753da77fb 100644 --- a/.agents/notes/implemented/feature/2026-11-05-session-panel.md +++ b/.agents/notes/implemented/feature/2026-11-05-session-panel.md @@ -24,7 +24,7 @@ Docking follows one persisted preference shared by every Session and defaults to Each section is one list registration with `id`, `order`, and a required `label`. The panel projects the live registrations into titles, draws each title, and renders the section body with `renderSlot(..., { only: id })`; a CSS `:has()` rule hides a section whose body rendered nothing, so a section opts out by rendering nothing and no effect reports visibility to the owner. Trailing title controls are a keyed slot addressed by the section `id`, and a section that several plugins share declares its own row slot, as the built-in Environment section does with `conversation.session.panel.environment.row`. Marks that must stay visible while the panel is hidden go in an indicator list over the toggle. -Rows from every contributor render through the plugin's `conversation.session.panel.row` Component Factory so icon, text, and trailing areas align across packages; a feature package cannot share its own row component with another feature package. +Rows from every contributor share one look through the panel's stylesheet instead of a shared component: each contributor writes its row's markup and marks the parts, and the panel lays them out, so icon, text, and trailing areas align across packages. A shared row component would receive each contributor's icon, text, and controls as React nodes in props, which the client rules forbid, and a feature package cannot share its own row component with another feature package. ### The turn rail sits at the start edge diff --git a/.agents/notes/implemented/feature/2026-11-05-session-panel.zh.md b/.agents/notes/implemented/feature/2026-11-05-session-panel.zh.md index 098fd9d467..a04ea8f169 100644 --- a/.agents/notes/implemented/feature/2026-11-05-session-panel.zh.md +++ b/.agents/notes/implemented/feature/2026-11-05-session-panel.zh.md @@ -24,7 +24,7 @@ Status: implemented 每个分栏是一次 list 注册,带 `id`、`order` 和必填的 `label`。面板把实时注册投影成标题并逐个绘制,再用 `renderSlot(..., { only: id })` 渲染分栏正文;CSS `:has()` 规则隐藏正文没有渲染内容的分栏,因此分栏不渲染任何内容即可退出,不需要 effect 向拥有者上报可见性。标题尾部控件是以分栏 `id` 为键的 keyed slot;多个插件共用的分栏声明自己的行 slot,内置「环境」分栏就以 `conversation.session.panel.environment.row` 这样做。面板隐藏时也要可见的标记放进开关上的角标列表。 -所有贡献方的行都通过插件的 Component Factory `conversation.session.panel.row` 渲染,使不同包的图标、文字与尾部区域对齐;功能包之间不能共享各自的行组件。 +各贡献方的行通过面板的样式表共享同一外观,而不是共享组件:各贡献方自己写行的标记并标出各个部分,由面板统一排版,使不同包的图标、文字与尾部区域对齐。共享的行组件要把各贡献方的图标、文字和控件作为 React 节点从 props 传入,这是客户端规则禁止的;功能包之间也不能共享各自的行组件。 ### 轮次轨道位于起始边 diff --git a/apps/web/tests/forge-panel.e2e.ts b/apps/web/tests/forge-panel.e2e.ts index e1a492e365..24ac04d6cf 100644 --- a/apps/web/tests/forge-panel.e2e.ts +++ b/apps/web/tests/forge-panel.e2e.ts @@ -647,6 +647,33 @@ async function chooseCardAction(page: Page, change: Locator, name: string, item: /** Accessible name of the panel toggle while a change request needs attention. */ const TOGGLE_ATTENTION = '会话面板 本会话的变更请求需要处理' +/** + * A Session panel row as the panel's row rules lay it out: its height, how far + * the centers of its icon and menu columns sit from its start and end edges + * (null for a part that takes no room), and the part a press reaches at its + * start edge and on its trailing part. + */ +function panelRowLayout(row: Locator) { + return row.evaluate((element) => { + const box = element.getBoundingClientRect() + const rectOf = (part: string): DOMRect | null => { + const rect = element.querySelector(`[data-row-part="${part}"]`)?.getBoundingClientRect() + return rect === undefined || rect.width === 0 ? null : rect + } + const partAt = (x: number, y: number): string | null => + document.elementFromPoint(x, y)?.closest('[data-row-part]')?.getAttribute('data-row-part') ?? null + const [icon, trailing, menu] = [rectOf('icon'), rectOf('trailing'), rectOf('menu')] + return { + marked: element.hasAttribute('data-session-panel-row'), + height: box.height, + iconCenter: icon === null ? null : icon.left + icon.width / 2 - box.left, + menuCenter: menu === null ? null : box.right - (menu.left + menu.width / 2), + startPress: partAt(box.left + 2, box.top + 2), + trailingPress: trailing === null ? null : partAt(trailing.left + trailing.width / 2, trailing.top + trailing.height / 2), + } + }) +} + function worktreeRecords(events: readonly SessionEvent[]): unknown[] { return events.flatMap((event) => { const record = pluginRecordOf(event) @@ -684,6 +711,12 @@ it.skipIf(MODE === 'record')('reads local Git with full access when the sandbox const local = page.locator('[data-forge-local]') await local.getByRole('button', { name: '本地变更 · 1 个文件,新增 1 行,删除 0 行', exact: true }).waitFor({ timeout: 20_000 }) await compareOrRefreshGolden(join(EXPECTED, 'full-access.expected.md'), await captureStableAria(page, '[data-forge-local]', scaffold.workspaceCwd), MODE) + // The panel lays the row out by its marks: one 28px line with the icon and the More button on the panel columns. + // The body is the row's button, so a press at the row's edge reaches it, while the diff size stays above it. + expect(await panelRowLayout(local)).toEqual({ marked: true, height: 28, iconCenter: 14, menuCenter: 14, startPress: 'body', trailingPress: 'trailing' }) + // This composition registers no directory menu entries: the checkout row's menu takes no room, and its body is not a button. + expect(await panelRowLayout(panel.locator('[data-forge-checkout]'))) + .toEqual({ marked: true, height: 28, iconCenter: 14, menuCenter: null, startPress: null, trailingPress: 'trailing' }) await local.getByRole('button', { name: '本地变更 · 1 个文件,新增 1 行,删除 0 行', exact: true }).click() await page.locator('[data-forge-diff-file="README.md"]').getByText('changed', { exact: true }).waitFor() diff --git a/apps/web/tests/session-panel-dock.e2e.ts b/apps/web/tests/session-panel-dock.e2e.ts deleted file mode 100644 index 92ea27624e..0000000000 --- a/apps/web/tests/session-panel-dock.e2e.ts +++ /dev/null @@ -1,161 +0,0 @@ -/** - * Session panel docking in the shipped Web composition. The panel's stylesheet - * decides whether the Chat View's end gutter holds the docked panel and tells - * the plugin through a 1px dock probe; jsdom cannot evaluate that stylesheet, - * so this measures the probe, the panel, and the toggle around the boundary. - */ -import { readFile } from 'node:fs/promises' -import { fileURLToPath } from 'node:url' -import type { Browser, Page } from 'playwright' -import { chromium } from 'playwright' -import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest' -import type { SessionId } from '@deepseek-ai/dsh-session' -import { brandString } from '@deepseek-ai/dsh-brand' -import { launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold } from './scaffold.ts' -import { newEnglishPage, saveFailureShot } from './support.ts' - -const FIXTURE = fileURLToPath(new URL('../../../snapshots/web/fresh-round-trip/session.v3.jsonl', import.meta.url)) -const MODE = webSnapshotMode() -const SEED_ID = brandString('session-panel-dock-web-e2e') -/** The default transcript width in a frame wide enough to dock. */ -const TRANSCRIPT = 880 -/** The gutter that holds the docked panel: 40px clear of the transcript, its 300px minimum width, and the 8px edge inset. */ -const DOCK_GUTTER = 348 - -/** What the layout says about docking: the gutter, the probe, the panel's presentation and insets, and the toggle. */ -function docking(page: Page) { - return page.evaluate(() => { - const layer = document.querySelector('[data-chat-aside]') - const column = document.querySelector('[data-chat-flow]') - const probe = document.querySelector('[data-session-panel-probe]') - const toggle = document.querySelector('[data-session-panel-toggle]') - if (layer === null || column === null || probe === null || toggle === null) { - throw new Error('aside layer, transcript column, dock probe, or panel toggle is missing') - } - const frame = layer.getBoundingClientRect() - const flow = column.getBoundingClientRect() - const panel = document.querySelector('[data-session-panel]') - const box = panel?.getBoundingClientRect() - return { - gutter: (frame.width - flow.width) / 2, - probe: probe.getBoundingClientRect().width, - presentation: panel?.dataset['sessionPanel'] ?? null, - expanded: toggle.getAttribute('aria-expanded'), - panel: box === undefined ? null : { width: box.width, clear: box.left - flow.right, edge: frame.right - box.right }, - } - }) -} - -describe.skipIf(MODE === 'record')('web e2e: Session panel docking', () => { - let scaffold: WebScaffold - let browser: Browser - let page: Page - let tripwire: ReturnType - /** Viewport width the application keeps outside the Chat frame. */ - let chrome = 0 - - /** Resize the window so the Chat View's end gutter is exactly `gutter`, and wait for the layout to follow. */ - async function setGutter(gutter: number): Promise { - await page.setViewportSize({ width: TRANSCRIPT + 2 * gutter + chrome, height: page.viewportSize()!.height }) - await expect.poll(async () => (await docking(page)).gutter, { timeout: 10_000 }).toBe(gutter) - } - - /** Wait until the panel shows this way (null: not at all) and its entrance has finished. */ - async function shows(presentation: 'docked' | 'overlay' | null): Promise { - await expect.poll(async () => (await docking(page)).presentation, { timeout: 10_000 }).toBe(presentation) - if (presentation === null) return - await page.locator('[data-session-panel]').evaluate(async (element) => { - await Promise.all(element.getAnimations().map(animation => animation.finished)) - }) - } - - beforeAll(async () => { - scaffold = await launchWebScaffold() - await seedSession(scaffold, await readFile(FIXTURE, 'utf8'), SEED_ID) - browser = await chromium.launch() - page = await newEnglishPage(browser) - await page.emulateMedia({ reducedMotion: 'reduce' }) - tripwire = watchConsole(page) - await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' }) - }, 120_000) - - /** Open the seeded Session and learn how much of the window lies outside the Chat frame. */ - async function openSession(): Promise { - if (chrome !== 0) return - const session = page.locator(`[data-row-key="session:${SEED_ID}"]`) - await expect.poll(async () => { - if (await session.isVisible()) return true - const group = page.locator('[role="treeitem"][aria-expanded]').first() - if (await group.count() > 0 && await group.getAttribute('aria-expanded') === 'false') await group.click() - return session.isVisible() - }, { timeout: 15_000 }).toBe(true) - await session.click() - await page.locator('[data-session-panel-probe]').waitFor({ state: 'attached', timeout: 30_000 }) - const frame = await page.locator('[data-chat-aside]').evaluate(element => element.getBoundingClientRect().width) - chrome = page.viewportSize()!.width - frame - } - - afterAll(async () => { - const failures: unknown[] = [] - try { await browser?.close() } catch (error) { failures.push(error) } - try { await scaffold?.close() } catch (error) { failures.push(error) } - if (failures.length > 0) throw new AggregateError(failures, 'Session panel docking teardown failed') - }) - - it('docks exactly from the gutter that holds the panel at its minimum width', async () => { - onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-dock')) - await openSession() - expect(Number.isInteger(chrome)).toBe(true) - - await setGutter(DOCK_GUTTER - 1) - await shows(null) - expect(await docking(page)).toEqual({ gutter: DOCK_GUTTER - 1, probe: 0, presentation: null, expanded: 'false', panel: null }) - - // Half a pixel short, the probe is half a pixel wide and the panel stays hidden. - await setGutter(DOCK_GUTTER - 0.5) - expect(await docking(page)).toEqual({ gutter: DOCK_GUTTER - 0.5, probe: 0.5, presentation: null, expanded: 'false', panel: null }) - - await setGutter(DOCK_GUTTER) - await shows('docked') - expect(await docking(page)).toEqual({ - gutter: DOCK_GUTTER, probe: 1, presentation: 'docked', expanded: 'true', panel: { width: 300, clear: 40, edge: 8 }, - }) - - // A wider gutter widens the panel to its maximum at the same edge inset; the probe stays 1px. - await setGutter(DOCK_GUTTER + 100) - expect(await docking(page)).toEqual({ - gutter: DOCK_GUTTER + 100, probe: 1, presentation: 'docked', expanded: 'true', panel: { width: 360, clear: 80, edge: 8 }, - }) - - await setGutter(DOCK_GUTTER - 1) - await shows(null) - expect((await docking(page)).expanded).toBe('false') - expect(tripwire.pageErrors).toEqual([]) - }) - - it('floats narrower than it docks, at the same edge inset, and docks once the gutter holds it', async () => { - onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-overlay')) - await openSession() - const toggle = page.locator('[data-session-panel-toggle]') - await setGutter(260) - await shows(null) - await toggle.click() - await shows('overlay') - const overlay = await docking(page) - expect(overlay).toMatchObject({ probe: 0, presentation: 'overlay', expanded: 'true', panel: { width: 280, edge: 8 } }) - // The overlay covers part of the transcript instead of keeping clear of it. - expect(overlay.panel?.clear).toBeLessThan(0) - - await page.keyboard.press('Escape') - await shows(null) - expect((await docking(page)).expanded).toBe('false') - - // An open overlay gives way to the docked panel when the window widens enough. - await toggle.click() - await shows('overlay') - await setGutter(DOCK_GUTTER) - await shows('docked') - expect(await docking(page)).toMatchObject({ probe: 1, expanded: 'true', panel: { width: 300, clear: 40, edge: 8 } }) - expect(tripwire.pageErrors).toEqual([]) - }) -}) diff --git a/apps/web/tests/session-panel-layout.e2e.ts b/apps/web/tests/session-panel-layout.e2e.ts new file mode 100644 index 0000000000..7d3186d0d4 --- /dev/null +++ b/apps/web/tests/session-panel-layout.e2e.ts @@ -0,0 +1,253 @@ +/** + * Session panel layout in the shipped Web composition. The panel's stylesheet + * decides whether the Chat View's end gutter holds the docked panel and tells + * the plugin through a 1px dock probe, and it lays out the rows that + * contributors mark. jsdom cannot evaluate that stylesheet, so this measures + * the probe, the panel, and the toggle around the docking boundary, and the + * working folder row without and with a directory context menu. + */ +import { readFile } from 'node:fs/promises' +import { fileURLToPath } from 'node:url' +import type { Browser, Page } from 'playwright' +import { chromium } from 'playwright' +import { afterAll, beforeAll, describe, expect, it, onTestFailed, onTestFinished } from 'vitest' +import { createLaunchEnvironmentSnapshot } from '@deepseek-ai/dsh-launch-environment' +import type { SessionId } from '@deepseek-ai/dsh-session' +import { brandString } from '@deepseek-ai/dsh-brand' +import { launchWebScaffold, seedSession, watchConsole, webSnapshotMode, type WebScaffold } from './scaffold.ts' +import { newEnglishPage, saveFailureShot } from './support.ts' + +const FIXTURE = fileURLToPath(new URL('../../../snapshots/web/fresh-round-trip/session.v3.jsonl', import.meta.url)) +const MODE = webSnapshotMode() +const SEED_ID = brandString('session-panel-layout-web-e2e') +/** The default transcript width in a frame wide enough to dock. */ +const TRANSCRIPT = 880 +/** The gutter that holds the docked panel: 40px clear of the transcript, its 300px minimum width, and the 8px edge inset. */ +const DOCK_GUTTER = 348 + +/** What the layout says about docking: the gutter, the probe, the panel's presentation and insets, and the toggle. */ +function docking(page: Page) { + return page.evaluate(() => { + const layer = document.querySelector('[data-chat-aside]') + const column = document.querySelector('[data-chat-flow]') + const probe = document.querySelector('[data-session-panel-probe]') + const toggle = document.querySelector('[data-session-panel-toggle]') + if (layer === null || column === null || probe === null || toggle === null) { + throw new Error('aside layer, transcript column, dock probe, or panel toggle is missing') + } + const frame = layer.getBoundingClientRect() + const flow = column.getBoundingClientRect() + const panel = document.querySelector('[data-session-panel]') + const box = panel?.getBoundingClientRect() + return { + gutter: (frame.width - flow.width) / 2, + probe: probe.getBoundingClientRect().width, + presentation: panel?.dataset['sessionPanel'] ?? null, + expanded: toggle.getAttribute('aria-expanded'), + panel: box === undefined ? null : { width: box.width, clear: box.left - flow.right, edge: frame.right - box.right }, + } + }) +} + +/** Open the seeded Session through the sidebar and wait for the panel's dock probe. */ +async function openSeed(page: Page): Promise { + const session = page.locator(`[data-row-key="session:${SEED_ID}"]`) + await expect.poll(async () => { + if (await session.isVisible()) return true + const group = page.locator('[role="treeitem"][aria-expanded]').first() + if (await group.count() > 0 && await group.getAttribute('aria-expanded') === 'false') await group.click() + return session.isVisible() + }, { timeout: 15_000 }).toBe(true) + await session.click() + await page.locator('[data-session-panel-probe]').waitFor({ state: 'attached', timeout: 30_000 }) +} + +/** Wait until the panel shows this way (null: not at all) and its entrance has finished. */ +async function shows(page: Page, presentation: 'docked' | 'overlay' | null): Promise { + await expect.poll(async () => (await docking(page)).presentation, { timeout: 10_000 }).toBe(presentation) + if (presentation === null) return + await page.locator('[data-session-panel]').evaluate(async (element) => { + await Promise.all(element.getAnimations().map(animation => animation.finished)) + }) +} + +/** + * The working folder row as laid out: its line, how far the centers of its + * icon and menu columns sit from its edges, the room after its text, and what + * the pointer state shows. `menu` is null while the menu part renders nothing. + */ +function rowLayout(page: Page) { + return page.locator('[data-session-panel] [data-session-panel-project]').evaluate((element) => { + const box = element.getBoundingClientRect() + const icon = element.querySelector('[data-row-part="icon"]')!.getBoundingClientRect() + const content = element.querySelector('[data-row-part="content"]')! + const menu = element.querySelector('[data-row-part="menu"]')! + const column = menu.getBoundingClientRect() + const button = menu.querySelector('button')?.getBoundingClientRect() + return { + height: box.height, + iconCenter: icon.left + icon.width / 2 - box.left, + iconSize: [icon.width, icon.height], + clipped: getComputedStyle(content).textOverflow, + afterText: box.right - content.getBoundingClientRect().right, + menu: button === undefined + ? null + : { + center: box.right - (column.left + column.width / 2), + target: [button.width, button.height], + opacity: getComputedStyle(menu).opacity, + }, + hovered: element.matches(':hover'), + highlighted: getComputedStyle(element).backgroundColor !== 'rgba(0, 0, 0, 0)', + } + }) +} + +describe.skipIf(MODE === 'record')('web e2e: Session panel layout', () => { + let scaffold: WebScaffold + let browser: Browser + let page: Page + let tripwire: ReturnType + /** Viewport width the application keeps outside the Chat frame. */ + let chrome = 0 + + /** Resize the window so the Chat View's end gutter is exactly `gutter`, and wait for the layout to follow. */ + async function setGutter(gutter: number): Promise { + await page.setViewportSize({ width: TRANSCRIPT + 2 * gutter + chrome, height: page.viewportSize()!.height }) + await expect.poll(async () => (await docking(page)).gutter, { timeout: 10_000 }).toBe(gutter) + } + + beforeAll(async () => { + scaffold = await launchWebScaffold() + await seedSession(scaffold, await readFile(FIXTURE, 'utf8'), SEED_ID) + browser = await chromium.launch() + page = await newEnglishPage(browser) + await page.emulateMedia({ reducedMotion: 'reduce' }) + tripwire = watchConsole(page) + await page.goto(scaffold.authenticatedUrl, { waitUntil: 'load' }) + }, 120_000) + + /** Open the seeded Session and learn how much of the window lies outside the Chat frame. */ + async function openSession(): Promise { + if (chrome !== 0) return + await openSeed(page) + const frame = await page.locator('[data-chat-aside]').evaluate(element => element.getBoundingClientRect().width) + chrome = page.viewportSize()!.width - frame + } + + afterAll(async () => { + const failures: unknown[] = [] + try { await browser?.close() } catch (error) { failures.push(error) } + try { await scaffold?.close() } catch (error) { failures.push(error) } + if (failures.length > 0) throw new AggregateError(failures, 'Session panel layout teardown failed') + }) + + it('docks exactly from the gutter that holds the panel at its minimum width', async () => { + onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-dock')) + await openSession() + expect(Number.isInteger(chrome)).toBe(true) + + await setGutter(DOCK_GUTTER - 1) + await shows(page, null) + expect(await docking(page)).toEqual({ gutter: DOCK_GUTTER - 1, probe: 0, presentation: null, expanded: 'false', panel: null }) + + // Half a pixel short, the probe is half a pixel wide and the panel stays hidden. + await setGutter(DOCK_GUTTER - 0.5) + expect(await docking(page)).toEqual({ gutter: DOCK_GUTTER - 0.5, probe: 0.5, presentation: null, expanded: 'false', panel: null }) + + await setGutter(DOCK_GUTTER) + await shows(page, 'docked') + expect(await docking(page)).toEqual({ + gutter: DOCK_GUTTER, probe: 1, presentation: 'docked', expanded: 'true', panel: { width: 300, clear: 40, edge: 8 }, + }) + + // A wider gutter widens the panel to its maximum at the same edge inset; the probe stays 1px. + await setGutter(DOCK_GUTTER + 100) + expect(await docking(page)).toEqual({ + gutter: DOCK_GUTTER + 100, probe: 1, presentation: 'docked', expanded: 'true', panel: { width: 360, clear: 80, edge: 8 }, + }) + + await setGutter(DOCK_GUTTER - 1) + await shows(page, null) + expect((await docking(page)).expanded).toBe('false') + expect(tripwire.pageErrors).toEqual([]) + }) + + it('floats narrower than it docks, at the same edge inset, and docks once the gutter holds it', async () => { + onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-overlay')) + await openSession() + const toggle = page.locator('[data-session-panel-toggle]') + await setGutter(260) + await shows(page, null) + await toggle.click() + await shows(page, 'overlay') + const overlay = await docking(page) + expect(overlay).toMatchObject({ probe: 0, presentation: 'overlay', expanded: 'true', panel: { width: 280, edge: 8 } }) + // The overlay covers part of the transcript instead of keeping clear of it. + expect(overlay.panel?.clear).toBeLessThan(0) + + await page.keyboard.press('Escape') + await shows(page, null) + expect((await docking(page)).expanded).toBe('false') + + // An open overlay gives way to the docked panel when the window widens enough. + await toggle.click() + await shows(page, 'overlay') + await setGutter(DOCK_GUTTER) + await shows(page, 'docked') + expect(await docking(page)).toMatchObject({ probe: 1, expanded: 'true', panel: { width: 300, clear: 40, edge: 8 } }) + expect(tripwire.pageErrors).toEqual([]) + }) + + it('lays the working folder row out by its marks, with no room or highlight for a menu that renders nothing', async () => { + onTestFailed(() => saveFailureShot(page, 'web-e2e-session-panel-row')) + await openSession() + await setGutter(DOCK_GUTTER + 100) + await shows(page, 'docked') + const row = page.locator('[data-session-panel] [data-session-panel-project]') + await row.waitFor() + await page.mouse.move(5, 5) + // This composition registers no directory menu entries, so the shared More button renders nothing: + // the text runs to the row's 6px padding, and the row has nothing to highlight for. + const resting = { height: 28, iconCenter: 14, iconSize: [16, 16], clipped: 'ellipsis', afterText: 6, menu: null, highlighted: false } + expect(await rowLayout(page)).toEqual({ ...resting, hovered: false }) + await row.hover() + expect(await rowLayout(page)).toEqual({ ...resting, hovered: true }) + expect(tripwire.pageErrors).toEqual([]) + }) + + it('puts a rendered menu on the panel end column and shows it, with the row highlight, on hover', async () => { + // The directory context menu comes from Open In; SSH facts keep it from probing this runner's native applications. + const withMenu = await launchWebScaffold({ openInAppEnvironment: createLaunchEnvironmentSnapshot([ + { source: 'process', values: { SSH_CONNECTION: '10.0.0.2 55000 10.0.0.9 22' } }, + ]) }) + onTestFinished(() => withMenu.close()) + await seedSession(withMenu, await readFile(FIXTURE, 'utf8'), SEED_ID) + const other = await newEnglishPage(browser) + onTestFinished(() => other.close()) + onTestFailed(() => saveFailureShot(other, 'web-e2e-session-panel-row-menu')) + await other.emulateMedia({ reducedMotion: 'reduce' }) + const errors = watchConsole(other) + // Wide enough for the gutter to hold the docked panel. + await other.setViewportSize({ width: 2200, height: 1000 }) + await other.goto(withMenu.authenticatedUrl, { waitUntil: 'load' }) + await openSeed(other) + await shows(other, 'docked') + const row = other.locator('[data-session-panel] [data-session-panel-project]') + await row.locator('[data-row-part="menu"] button').waitFor({ state: 'attached' }) + await other.mouse.move(5, 5) + // The 16px menu column and the 8px gap before it follow the text; the 24px target reaches past the column. + const resting = { height: 28, iconCenter: 14, iconSize: [16, 16], clipped: 'ellipsis', afterText: 30 } + expect(await rowLayout(other)).toEqual({ + ...resting, menu: { center: 14, target: [24, 24], opacity: '0' }, hovered: false, highlighted: false, + }) + await row.hover() + await expect.poll(async () => (await rowLayout(other)).menu?.opacity).toBe('1') + expect(await rowLayout(other)).toEqual({ + ...resting, menu: { center: 14, target: [24, 24], opacity: '1' }, hovered: true, highlighted: true, + }) + await other.mouse.move(5, 5) + await expect.poll(async () => (await rowLayout(other)).highlighted).toBe(false) + expect(errors.pageErrors).toEqual([]) + }) +}) diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 0a672d96b2..0a07dccec6 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -25,7 +25,7 @@ "exclude": [ "tests/home-whale.e2e.ts", "tests/sidebar-drawer.e2e.ts", - "tests/session-panel-dock.e2e.ts", + "tests/session-panel-layout.e2e.ts", "tests/creation-recommendations.e2e.ts", "tests/plugin-recommendations.e2e.ts", "tests/japanese-plugin-metadata.e2e.ts", diff --git a/packages/client/ui-session-panel/README.i18n.yaml b/packages/client/ui-session-panel/README.i18n.yaml index c51e3e02b8..4d3d0b7bdd 100644 --- a/packages/client/ui-session-panel/README.i18n.yaml +++ b/packages/client/ui-session-panel/README.i18n.yaml @@ -21,11 +21,11 @@ en: 67b33b9f412a687d zh: 2a9b8c89c8bb22e4 /deepseek-ai-dsh-client-ui-session-panel/use-this-package/contribute-a-section: - en: d9be9db35539e9b4 - zh: c2597c59f94d594e + en: dd2712df8a0455a2 + zh: c4d98d0edc2f7d52 /deepseek-ai-dsh-client-ui-session-panel/understand-the-implementation: - en: e3fc397ec6c8ef3b - zh: 097a67dadb267010 + en: e414b3b6a3aef7fc + zh: 384ad365ae5529a9 /deepseek-ai-dsh-client-ui-session-panel/further-exploration: en: 09b403af819bd155 zh: e949998de4794393 diff --git a/packages/client/ui-session-panel/README.md b/packages/client/ui-session-panel/README.md index b00d1c0f83..b7488f7d41 100644 --- a/packages/client/ui-session-panel/README.md +++ b/packages/client/ui-session-panel/README.md @@ -44,7 +44,20 @@ Plugins share a title by registering rows in a section owner's row slot. The bui Marks that must stay visible while the panel is hidden, such as an attention dot, go in the `conversation.session.panel.indicator` list. Each occupant is one element: the toggle sizes it to a 6px dot at the glyph's corner, and the occupant sets its `background` and includes text that names it, which becomes part of the toggle's accessible name. Occupants overlap, and a higher `order` paints above a lower one. The `panelShown` owner prop lets a mark that only repeats the panel's content render nothing while the panel shows. Subagents and Background jobs show a blue dot while work runs and the panel does not show (orders 10 and 20); the forge bundle's red attention dot (order 100) paints above them and stays while the panel shows. -The plugin offers its row as the `conversation.session.panel.row` Component Factory. Sections and Environment rows from every package render their rows with `renderFactorySlot('conversation.session.panel.row', props)`, so icon, text, and trailing areas line up across sections. A row has a 16px decorative icon that inherits the row ink, single-line content that clips with an ellipsis, and an optional trailing value or control. `menu` holds row actions, such as a More button, after the trailing area in a 16px column whose center sits 14px from the row's end; a plain `button` there gets a 24px target and a tertiary glyph that darkens on hover without a fill, so it needs no tooltip of its own. They show on row hover, on focus inside the row, and while one has its menu open, and always without hover. `onActivate` makes the whole row one button while the trailing area and the menu stay separate controls, and `actionLabel` names that button when its content does not describe the action, starting with the visible text; a row with an action or row actions fills as a whole on hover and while one of its menus is open. `detail` adds a second line in smaller tertiary type that clips with an ellipsis, such as the consequence of a status or a command to run; the icon stays beside the first line and the trailing area and menu center on the row. `className` adds to the row's class, and `attributes`, such as `role`, `data-*` markers, and context-menu trigger props, reach the row element; other props are ignored. +Rows share one look without sharing a component. A section's component, or an Environment row entry, writes its row's markup and marks the parts, and the panel's stylesheet lays them out, so icon, text, and trailing areas line up across packages while each package owns what its row contains. + +| Mark | Part | +|---|---| +| `data-session-panel-row` | The row: one 28px line. A row with an action or a menu highlights as a whole on hover and while one of its menus is open. | +| `data-row-part="body"` | The icon and the text. A `} - {trailing !== undefined && {trailing}} - {menu !== undefined && {menu}} - - ) -} diff --git a/packages/client/ui-session-panel/src/client/ProjectRow.tsx b/packages/client/ui-session-panel/src/client/ProjectRow.tsx index add253e0da..15f64d245d 100644 --- a/packages/client/ui-session-panel/src/client/ProjectRow.tsx +++ b/packages/client/ui-session-panel/src/client/ProjectRow.tsx @@ -3,7 +3,6 @@ import type { ReactNode } from 'react' import { IconFolderCloseRegular, Tooltip } from '@deepseek-ai/dsh-client-ui-primitives' import { abbreviateHomePath, pathPartsOf } from '@deepseek-ai/dsh-util-workspace-path' import type {} from '@deepseek-ai/dsh-working-directory/types' -import { PanelRow } from './PanelRow.tsx' import type { ProjectRowProps } from './slots.ts' import css from './ProjectRow.module.css' @@ -34,17 +33,19 @@ export function ProjectRow({ const parent = ROOT.test(directory) ? directory : directory.replace(/[/\\]+$/, '') const target = { kind: 'directory', value: { sessionId, path } } as const return ( - } - menu={renderFactorySlot('contextMenu.button', { target, label: t('project.actions') })} - attributes={{ ...getTriggerProps(target), 'data-session-panel-project': '' }} - > - - - {name} - {parent !== '' && {parent}} +
+ + + + + + {name} + {parent !== '' && {parent}} + + - - + + {renderFactorySlot('contextMenu.button', { target, label: t('project.actions') })} +
) } diff --git a/packages/client/ui-session-panel/src/client/SessionPanel.module.css b/packages/client/ui-session-panel/src/client/SessionPanel.module.css index 2bd861ff5e..85f933374b 100644 --- a/packages/client/ui-session-panel/src/client/SessionPanel.module.css +++ b/packages/client/ui-session-panel/src/client/SessionPanel.module.css @@ -137,3 +137,207 @@ animation: none; } } + +/* Rows. The rows of every section share one look without sharing a + component: each contributor writes its row's markup and marks the parts, + and these rules lay them out. + + [data-session-panel-row] the row: one 28px line + [data-row-part='body'] the icon and the text; a }> - Local changes -
, - ) - fireEvent.click(screen.getByRole('button', { name: 'Local changes' })) - expect(onActivate).toHaveBeenCalledTimes(1) - fireEvent.click(screen.getByRole('button', { name: 'More' })) - expect(onTrailing).toHaveBeenCalledTimes(1) - expect(onActivate).toHaveBeenCalledTimes(1) - }) - - it('names the button with the action label', () => { - const onActivate = vi.fn() - render(} onActivate={onActivate} actionLabel="View the changes: 2 files">Local changes) - fireEvent.click(screen.getByRole('button', { name: 'View the changes: 2 files' })) - expect(onActivate).toHaveBeenCalledTimes(1) - }) - - it('places row actions after the trailing area and marks only rows with an action or row actions as interactive', () => { - const view = render( - } trailing={value} menu={}>Project, - ) - const row = view.container.querySelector('[data-panel-row]') as HTMLElement - expect([...row.children].map(child => child.textContent)).toEqual(['Project', 'value', 'More']) - const interactive = row.className - cleanup() - const plain = render(} trailing={value}>Project) - const staticRow = plain.container.querySelector('[data-panel-row]') as HTMLElement - expect(staticRow.children).toHaveLength(2) - expect(staticRow.className).not.toBe(interactive) - }) - - it('puts a detail line under the content and keeps the trailing area beside both lines', () => { - const view = render( - } detail={gh auth login} trailing={}>Sign in, - ) - const row = view.container.querySelector('[data-panel-row]') as HTMLElement - const lines = screen.getByText('Sign in').parentElement as HTMLElement - expect([...lines.children].map(line => line.textContent)).toEqual(['Sign in', 'gh auth login']) - expect([...row.children].map(child => child.textContent)).toEqual(['Sign ingh auth login', 'Copy']) - const plain = render(}>Sign in).container.querySelector('[data-panel-row]') as HTMLElement - expect(row.className).not.toBe(plain.className) - }) - - it('puts its attributes, such as context-menu handlers and markers, and its class on the row element', () => { - const onContextMenu = vi.fn() - const view = render( - } className="placed" attributes={{ onContextMenu, tabIndex: 0, 'data-marker': 'on' }}>Row, - ) - const row = view.container.querySelector('[data-panel-row]') as HTMLElement - expect(row.className).toContain('placed') - expect(row.tabIndex).toBe(0) - expect(row.getAttribute('data-marker')).toBe('on') - fireEvent.contextMenu(row) - expect(onContextMenu).toHaveBeenCalledTimes(1) - }) - - it('leaves props outside its own, such as a Factory occurrence adds, off the row element', () => { - const extra = { renderFactorySlot: vi.fn(), useFactorySlot: vi.fn(), useWorkspaces: vi.fn() } - const view = render(, children: 'Row', ...extra }} />) - const row = view.container.querySelector('[data-panel-row]') as HTMLElement - expect(row.getAttributeNames().sort()).toEqual(['class', 'data-panel-row']) - }) -}) diff --git a/packages/client/ui-session-panel/tests/session-panel-styles.client.spec.ts b/packages/client/ui-session-panel/tests/session-panel-styles.client.spec.ts index 1b82c25b9b..f33d439043 100644 --- a/packages/client/ui-session-panel/tests/session-panel-styles.client.spec.ts +++ b/packages/client/ui-session-panel/tests/session-panel-styles.client.spec.ts @@ -1,8 +1,9 @@ /** - * The Session panel's docking geometry as CSS text. jsdom has no layout, so - * the component suite cannot show that the dock probe is 1px wide exactly - * from the gutter that holds the docked panel; this reads the declarations - * and evaluates them for gutters around that boundary. + * The Session panel's stylesheet as CSS text. jsdom has no layout, so the + * component suite cannot show that the dock probe is 1px wide exactly from + * the gutter that holds the docked panel, or that marked rows get one + * geometry; this reads the declarations and evaluates the docking ones for + * gutters around that boundary. */ import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' @@ -70,3 +71,64 @@ describe('SessionPanel.module.css docking geometry', () => { expect(declarationsOf(".panel[data-session-panel='overlay']")['width']).toBe('min(280px, calc(100% - 2 * var(--panel-edge)))') }) }) + +describe('SessionPanel.module.css row rules', () => { + /** A rule for marked row markup: `.panel :where()`. */ + const row = (inner: string, tail = ''): Record => declarationsOf(`.panel :where(${inner})${tail}`) + + it('lays a marked row out as one 28px line with the icon and the menu on fixed columns', () => { + expect(row('[data-session-panel-row]')).toMatchObject({ + 'display': 'flex', 'align-items': 'center', 'gap': '8px', 'min-height': '28px', 'padding': '0 6px', + }) + expect(row("[data-session-panel-row] > [data-row-part='body']")).toMatchObject({ flex: '1 1 auto', height: '28px', gap: '8px' }) + // 6px of padding and half of the 16px box put the icon's center 14px from the row's start, and the menu's from its end. + expect(row("[data-session-panel-row] [data-row-part='icon']")).toMatchObject({ width: '16px', height: '16px', flex: 'none' }) + expect(row("[data-session-panel-row] > [data-row-part='menu']")).toMatchObject({ 'width': '16px', 'justify-content': 'center' }) + expect(row("[data-session-panel-row] [data-row-part='content']")).toMatchObject({ + 'overflow': 'hidden', 'text-overflow': 'ellipsis', 'white-space': 'nowrap', + }) + }) + + it('grows a row with a detail line and keeps the icon level with the first line', () => { + const tall = "[data-session-panel-row] > [data-row-part='body']:has([data-row-part='detail'])" + expect(row(tall)).toEqual({ 'align-items': 'flex-start', 'height': 'auto', 'padding': '4px 0' }) + expect(row(`${tall} > [data-row-part='icon']`)).toEqual({ height: '20px' }) + expect(row("[data-session-panel-row] [data-row-part='lines']")).toMatchObject({ 'display': 'flex', 'flex-direction': 'column', 'min-width': '0' }) + expect(row("[data-session-panel-row] [data-row-part='detail']")).toMatchObject({ + 'color': 'var(--dsw-alias-label-tertiary)', 'font-size': '12px', 'line-height': '17px', 'text-overflow': 'ellipsis', 'white-space': 'nowrap', + }) + // The two-line rules follow the one-line ones they adjust, since every rule for a part has the same specificity. + const order = (selector: string): number => { + const at = css.indexOf(`.panel :where(${selector}) {`) + expect(at).toBeGreaterThan(-1) + return at + } + expect(order(tall)).toBeGreaterThan(order("[data-session-panel-row] > button[data-row-part='body']")) + expect(order(`${tall} > [data-row-part='icon']`)).toBeGreaterThan(order("[data-session-panel-row] [data-row-part='icon']")) + }) + + it('makes a button body the action of the whole row and rings the row when it has keyboard focus', () => { + expect(row("[data-session-panel-row] > button[data-row-part='body']", '::after')).toMatchObject({ position: 'absolute', inset: '0' }) + expect(row("[data-session-panel-row] > [data-row-part='trailing'], [data-session-panel-row] > [data-row-part='menu']")) + .toMatchObject({ 'position': 'relative', 'z-index': '1' }) + expect(row("[data-session-panel-row]:has(> button[data-row-part='body']:focus-visible)")['outline-offset']).toBe('-2px') + }) + + it('gives a plain button in the menu a 24px target and a tertiary glyph without a fill', () => { + expect(row("[data-session-panel-row] > [data-row-part='menu']", ' button')).toMatchObject({ + width: '24px', height: '24px', margin: '-4px', background: 'transparent', color: 'var(--dsw-alias-label-tertiary)', + }) + }) + + it('highlights only a row with an action or a menu that renders something, and keeps an open menu and its row shown', () => { + const interactive = "[data-session-panel-row]:has(> button[data-row-part='body'], > [data-row-part='menu']:not(:empty))" + expect(row("[data-session-panel-row] > [data-row-part='menu']:empty")).toEqual({ display: 'none' }) + expect(row(`${interactive}:has([aria-expanded='true'])`)['background']).toBe('var(--dsw-alias-interactive-bg-hover)') + expect(row("[data-session-panel-row] > [data-row-part='menu']:has([aria-expanded='true'])")['opacity']).toBe('1') + // Hover rules stay inside the hover media query, where the menu hides until the row is hovered or focused. + const hover = /@media \(hover: hover\) \{([\s\S]*?)\n\}/.exec(css)?.[1] ?? '' + expect(hover).toContain(`.panel :where(${interactive}:hover)`) + expect(hover).toMatch(/\[data-row-part='menu'\]\) \{\s*opacity: 0;/) + expect(css.replace(/@media \(hover: hover\) \{[\s\S]*?\n\}/g, '')).not.toContain(':hover') + }) +}) diff --git a/packages/experimental/client-ui-forge/src/client/ChangeRequestsSection.tsx b/packages/experimental/client-ui-forge/src/client/ChangeRequestsSection.tsx index 8f2ec3e45a..246cec346e 100644 --- a/packages/experimental/client-ui-forge/src/client/ChangeRequestsSection.tsx +++ b/packages/experimental/client-ui-forge/src/client/ChangeRequestsSection.tsx @@ -5,7 +5,7 @@ import { Button, IconWarningTriangleOutlineRegular, MarqueeText, useHoverMarquee, } from '@deepseek-ai/dsh-client-ui-primitives' import type { - HostObservable, InjectFace, PropsLocale, PropsRenderFactories, PropsRenderSlots, PropsRuntime, PropsStore, + HostObservable, InjectFace, PropsLocale, PropsRenderSlots, PropsRuntime, PropsStore, } from '@deepseek-ai/dsh-client-ui-slots' import type { ForgeReadiness, MergeRequest } from '@deepseek-ai/dsh-experimental-forge/types' import type {} from '@deepseek-ai/dsh-client-ui-session-panel/client' @@ -59,7 +59,6 @@ export interface ChangeRequestsSectionInjected { export type ChangeRequestsSectionProps = PropsRuntime<'conversation.session.panel.section'> & Pick, 'renderSlot'> - & PropsRenderFactories & InjectFace & PropsStore> & PropsLocale @@ -97,11 +96,11 @@ function signInNeedOf(state: ForgePanelState): SignInNeed | null { * sign-in check. A reason the host gave shows from the info button; a clipped * title or command crawls into view while the pointer rests on the row. */ -function SignInRow({ need, copyText, renderFactorySlot, t }: { +function SignInRow({ need, copyText, t }: { readonly need: SignInNeed readonly copyText: (text: string) => void readonly t: Translate -} & PropsRenderFactories): ReactNode { +}): ReactNode { const titleRef = useRef(null) const commandRef = useRef(null) const titleMarquee = useHoverMarquee(titleRef) @@ -109,21 +108,37 @@ function SignInRow({ need, copyText, renderFactorySlot, t }: { const { host, forge, readiness } = need const unavailable = readiness.state === 'unavailable' const command = !unavailable && forge === 'github' ? `gh auth login --hostname ${host}` : undefined - const reason = command === undefined && readiness.message !== null && readiness.message !== '' - ? - : undefined const marquee = command === undefined ? titleMarquee : commandMarquee - return renderFactorySlot('conversation.session.panel.row', { - icon: , - attributes: { role: 'status', 'data-forge-signin': readiness.state, onPointerEnter: marquee.enter, onPointerLeave: marquee.leave }, - detail: command === undefined ? undefined : {command}, - trailing: command === undefined ? reason : ( + let trailing: ReactNode + if (command !== undefined) { + trailing = ( - ), - children: {t(unavailable ? 'signin.unavailable' : 'signin.title', { host })}, - }) + ) + } + else if (readiness.message !== null && readiness.message !== '') { + trailing = + } + const title = ( + + {t(unavailable ? 'signin.unavailable' : 'signin.title', { host })} + + ) + return ( +
+ + + {command === undefined ? title : ( + + {title} + {command} + + )} + + {trailing !== undefined && {trailing}} +
+ ) } /** @@ -139,8 +154,7 @@ function SignInRow({ need, copyText, renderFactorySlot, t }: { */ export function ChangeRequestsSection({ usePanel, useLocale, dismissOverlay, refresh, remove, markReady, merge, readChecks, - rerunChecks, requestReviews, reviewerCandidates, updateBranch, openLink, copyText, viewChanges, useStore, actions: store, renderSlot, - renderFactorySlot, t, + rerunChecks, requestReviews, reviewerCandidates, updateBranch, openLink, copyText, viewChanges, useStore, actions: store, renderSlot, t, }: ChangeRequestsSectionProps): ReactNode { const snapshot = usePanel(current => current) const locale = useLocale(value => value) @@ -164,7 +178,7 @@ export function ChangeRequestsSection({ const now = Date.now() return (
- {signIn !== null && } + {signIn !== null && } {state.changeRequests.length > 0 && (
    {state.changeRequests.map(entry => ( diff --git a/packages/experimental/client-ui-forge/src/client/EnvironmentRows.tsx b/packages/experimental/client-ui-forge/src/client/EnvironmentRows.tsx index cf348e7bbe..349493181b 100644 --- a/packages/experimental/client-ui-forge/src/client/EnvironmentRows.tsx +++ b/packages/experimental/client-ui-forge/src/client/EnvironmentRows.tsx @@ -52,7 +52,6 @@ export interface LocalChangesRowInjected { /** Full props of the local changes row. */ export type LocalChangesRowProps = PropsRuntime<'conversation.session.panel.environment.row'> - & PropsRenderFactories & InjectFace & PropsLocale @@ -91,32 +90,40 @@ export function CheckoutRow({ const label = checkoutLabel(state, home, t) if (label === undefined) { if (state.checkout.state !== 'failed') return null - return renderFactorySlot('conversation.session.panel.row', { - className: css.envRow, - icon: , - attributes: { 'data-forge-checkout': '', 'data-failed': '' }, - trailing: , - children: {t('checkout.failed')}, - }) + return ( +
    + + + {t('checkout.failed')} + + +
    + ) } const target = { kind: 'directory', value: { sessionId, path: label.path } } as const - const icon = label.missing - ? - : const name = [label.detached ? t('checkout.detached') : undefined, label.name ?? undefined] .filter(part => part !== undefined).join(' · ') - return renderFactorySlot('conversation.session.panel.row', { - className: css.envRow, - icon, - attributes: { - ...getTriggerProps(target), - 'data-forge-checkout': '', - 'data-missing': label.missing ? '' : undefined, - onPointerEnter: marquee.enter, - onPointerLeave: marquee.leave, - }, - trailing: ( - <> + return ( +
    + + + + + {name} + + + + {label.kind} {label.missing && (
    + ) } /** Business face of the connection row. */ @@ -154,7 +160,6 @@ export interface ConnectionRowInjected { /** Full props of the connection row. */ export type ConnectionRowProps = PropsRuntime<'conversation.session.panel.environment.row'> - & PropsRenderFactories & InjectFace & PropsLocale @@ -165,17 +170,21 @@ export type ConnectionRowProps = * @param props - panel snapshot hook, reconnect action, and copy. * @returns the row, or null while the stream is open. */ -export function ConnectionRow({ usePanel, reconnect, renderFactorySlot, t }: ConnectionRowProps): ReactNode { +export function ConnectionRow({ usePanel, reconnect, t }: ConnectionRowProps): ReactNode { const disconnected = usePanel(snapshot => snapshot.disconnected) if (!disconnected) return null - return renderFactorySlot('conversation.session.panel.row', { - className: css.envRow, - icon: , - attributes: { role: 'status', 'data-forge-connection': '' }, - detail: t('connection.detail'), - trailing: , - children: {t('connection.title')}, - }) + return ( +
    + + + + {t('connection.title')} + {t('connection.detail')} + + + +
    + ) } /** @@ -187,7 +196,7 @@ export function ConnectionRow({ usePanel, reconnect, renderFactorySlot, t }: Con * @returns the row, or null while the branch changes no files. */ export function LocalChangesRow({ - usePanel, dismissOverlay, viewLocalChanges, createChangeRequest, renderFactorySlot, t, + usePanel, dismissOverlay, viewLocalChanges, createChangeRequest, t, }: LocalChangesRowProps): ReactNode { const local = usePanel(snapshot => snapshot.state?.local ?? null) const creatable = usePanel(snapshot => snapshot.state !== null && snapshot.state.repository !== null @@ -205,46 +214,51 @@ export function LocalChangesRow({ viewLocalChanges() dismissOverlay() } - return renderFactorySlot('conversation.session.panel.row', { - className: css.envRow, - icon: , - onActivate: view, - actionLabel: t('changes.local.viewAria', { count, added: additions, deleted: deletions }), - attributes: { 'data-forge-local': '' }, - trailing: ( - - {`+${String(additions)}`} - {`−${String(deletions)}`} + return ( +
    + + + + {`+${String(additions)}`} + {`−${String(deletions)}`} + - ), - menu: ( - { setOpen(false) }} - portal - align="end" - anchor={( - - )} - items={[ - { id: 'view', label: t('change.viewChanges') }, - ...creatable ? [{ id: 'create', label: t('changes.local.create') }] : [], - ]} - onSelect={(id) => { - setOpen(false) - if (id === 'create') createChangeRequest() - else view() - }} - /> - ), - children: t('changes.local.summary', { count }), - }) + + { setOpen(false) }} + portal + align="end" + anchor={( + + )} + items={[ + { id: 'view', label: t('change.viewChanges') }, + ...creatable ? [{ id: 'create', label: t('changes.local.create') }] : [], + ]} + onSelect={(id) => { + setOpen(false) + if (id === 'create') createChangeRequest() + else view() + }} + /> + +
    + ) } diff --git a/packages/experimental/client-ui-forge/src/client/Forge.module.css b/packages/experimental/client-ui-forge/src/client/Forge.module.css index 6918fa3b26..002a582fb6 100644 --- a/packages/experimental/client-ui-forge/src/client/Forge.module.css +++ b/packages/experimental/client-ui-forge/src/client/Forge.module.css @@ -463,7 +463,7 @@ font-variant-numeric: tabular-nums; } -/* Environment rows: the kind or size trails the name; PanelRow reveals the More button. */ +/* Environment rows: the kind or size trails the name; the Session panel's row rules reveal the More button. */ .envName { display: block; overflow: hidden; diff --git a/packages/experimental/client-ui-forge/tests/panel-entries.client.spec.tsx b/packages/experimental/client-ui-forge/tests/panel-entries.client.spec.tsx index 63fc85d4c6..8cbfc8e9be 100644 --- a/packages/experimental/client-ui-forge/tests/panel-entries.client.spec.tsx +++ b/packages/experimental/client-ui-forge/tests/panel-entries.client.spec.tsx @@ -24,7 +24,6 @@ import type { PanelSnapshot } from '../src/client/source.ts' import type { ForgePanelChangeRequest, ForgePanelState } from '../src/types.ts' import { createChangeRequestsSectionStore } from '../src/client/change-requests-store.ts' import { created, entry, ready, removed, snapshot, worktree } from './client-fixtures.client.ts' -import { renderPanelRows } from './panel-row-factory.client.tsx' afterEach(cleanup) @@ -35,6 +34,24 @@ function panelStore(state: ForgePanelState | null, disconnected = false) { return createSnapshotStore({ state, disconnected }) } +/** + * The parts a row marks for the Session panel's row rules, nested as in its + * markup, with `button:` before a part that is a button. + * @param row - the row element. + * @returns the parts, or null when the element is not marked as a panel row. + */ +function rowParts(row: Element): string | null { + const partsOf = (element: Element): string => [...element.children] + .filter(child => child.hasAttribute('data-row-part')) + .map((child) => { + const name = `${child.tagName === 'BUTTON' ? 'button:' : ''}${child.getAttribute('data-row-part') ?? ''}` + const inner = partsOf(child) + return inner === '' ? name : `${name}(${inner})` + }) + .join(' ') + return row.hasAttribute('data-session-panel-row') ? partsOf(row) : null +} + /** One Session's section store, as the registration mints it. */ type SectionStore = ReturnType['create']> @@ -53,7 +70,6 @@ function section(state: ForgePanelState | null, options: { disconnected?: boolea dismissOverlay: vi.fn<() => void>(), // Plugins' card actions: a marker naming the change request it was drawn for. renderSlot: vi.fn((_name: string, owner: { url: string }) => ), - renderFactorySlot: renderPanelRows(), } const props = { sessionId: SESSION, @@ -66,7 +82,7 @@ function section(state: ForgePanelState | null, options: { disconnected?: boolea t, } as Pick as ChangeRequestsSectionProps const view = render() return { view, panel, store, ...handlers } @@ -202,6 +218,9 @@ describe('ChangeRequestsSection', () => { const row = b.view.getByRole('status') expect(root.firstElementChild).toBe(row) expect(row.getAttribute('data-forge-signin')).toBe('unauthenticated') + // The command is the row's detail line, and Copy its trailing control. + expect(rowParts(row)).toBe('body(icon lines(content detail)) trailing') + expect(row.querySelector('[data-row-part="detail"]')?.textContent).toBe('gh auth login --hostname github.com') expect(within(row).getByText('Sign in to github.com')).toBeTruthy() expect(within(row).getByText('gh auth login --hostname github.com')).toBeTruthy() const copy = within(row).getByRole('button', { name: en['signin.copy'] }) @@ -227,6 +246,7 @@ describe('ChangeRequestsSection', () => { })) const row = b.view.getByRole('status') expect([row.textContent, row.querySelector('code, [data-forge-signin] button:not([data-forge-reason])')]).toEqual([title, null]) + expect(rowParts(row)).toBe('body(icon content) trailing') const reason = within(row).getByRole('button', { name: en['reason.show'] }) fireEvent.click(reason) expect(screen.getByRole('tooltip').textContent).toBe('token expired') @@ -242,6 +262,7 @@ describe('ChangeRequestsSection', () => { readiness: { state, message: null }, })) expect(within(b.view.getByRole('status')).queryByRole('button')).toBeNull() + expect(rowParts(b.view.getByRole('status'))).toBe('body(icon content)') }) it.each([ @@ -285,7 +306,7 @@ describe('CheckoutRow', () => { const restore = vi.fn<() => void>() const refreshIfStale = vi.fn<() => void>() const opened: ContextMenuTarget[] = [] - const renderFactorySlot = renderPanelRows((_name, input: { label: string }) => ) + const renderFactorySlot = vi.fn((_name: string, input: { label: string }) => ) const props = { sessionId: SESSION, usePanel: bindSnapshotSelector(panel), @@ -337,6 +358,7 @@ describe('CheckoutRow', () => { const b = row(ready({ checkout: { state: 'failed', message: 'sandbox runner unavailable' } })) const element = b.element() as HTMLElement expect(element.hasAttribute('data-failed')).toBe(true) + expect(rowParts(element)).toBe('body(icon content) trailing') expect(element.textContent).toBe(en['checkout.failed']) expect(within(element).getByText(en['checkout.failed']).hasAttribute('tabindex')).toBe(false) const reason = within(element).getByRole('button', { name: en['reason.show'] }) @@ -361,6 +383,11 @@ describe('CheckoutRow', () => { const b = row(ready(), '/work') const element = b.element() as HTMLElement expect(element.textContent).toBe(`main${en['checkout.project']}${en['checkout.projectActions']}`) + // The kind trails the branch name, and the More button is the row menu. + expect(rowParts(element)).toBe('body(icon content) trailing menu') + expect(element.querySelector('[data-row-part="icon"]')?.getAttribute('aria-hidden')).toBe('true') + expect(element.querySelector('[data-row-part="trailing"]')?.textContent).toBe(en['checkout.project']) + expect(element.querySelector('[data-row-part="menu"]')?.textContent).toBe(en['checkout.projectActions']) vi.useFakeTimers() fireEvent.pointerEnter(within(element).getByText('main')) act(() => { vi.advanceTimersByTime(499) }) @@ -419,6 +446,8 @@ describe('CheckoutRow', () => { const b = row(removed()) const element = b.element() as HTMLElement expect(element.hasAttribute('data-missing')).toBe(true) + // A removed worktree has no directory to act on, so the row has no menu part. + expect(rowParts(element)).toBe('body(icon content) trailing') expect(within(element).getByText('dsh/0a1b2c3d')).toBeTruthy() expect(within(element).getByText(en['missing.title'])).toBeTruthy() expect(b.renderFactorySlot).not.toHaveBeenCalledWith('contextMenu.button', expect.anything()) @@ -438,8 +467,8 @@ describe('ConnectionRow', () => { function row(state: ForgePanelState | null, disconnected: boolean) { const panel = panelStore(state, disconnected) const reconnect = vi.fn<() => void>() - const props = { sessionId: SESSION, usePanel: bindSnapshotSelector(panel), reconnect, renderFactorySlot: renderPanelRows(), t } as - Pick as ConnectionRowProps + const props = { sessionId: SESSION, usePanel: bindSnapshotSelector(panel), reconnect, t } as + Pick as ConnectionRowProps return { view: render(), panel, reconnect } } @@ -454,6 +483,8 @@ describe('ConnectionRow', () => { const b = row(state, true) const status = b.view.getByRole('status') expect(status.hasAttribute('data-forge-connection')).toBe(true) + expect(rowParts(status)).toBe('body(icon lines(content detail)) trailing') + expect(status.querySelector('[data-row-part="detail"]')?.textContent).toBe(en['connection.detail']) expect(within(status).getByText(en['connection.title'])).toBeTruthy() expect(within(status).getByText(en['connection.detail'])).toBeTruthy() fireEvent.click(within(status).getByRole('button', { name: en.retry })) @@ -475,10 +506,9 @@ describe('LocalChangesRow', () => { const createChangeRequest = vi.fn<() => void>() const dismissOverlay = vi.fn<() => void>() const props = { - sessionId: SESSION, usePanel: bindSnapshotSelector(panel), dismissOverlay, viewLocalChanges, createChangeRequest, - renderFactorySlot: renderPanelRows(), t, + sessionId: SESSION, usePanel: bindSnapshotSelector(panel), dismissOverlay, viewLocalChanges, createChangeRequest, t, } as Pick as LocalChangesRowProps + 'sessionId' | 'usePanel' | 'dismissOverlay' | 'viewLocalChanges' | 'createChangeRequest' | 't'> as LocalChangesRowProps const view = render() return { view, viewLocalChanges, createChangeRequest, dismissOverlay } } @@ -499,6 +529,8 @@ describe('LocalChangesRow', () => { it('sums the branch changes, opens them, and asks the Agent for a change request', () => { const b = row(ready({ local })) const element = b.view.container.querySelector('[data-forge-local]') as HTMLElement + // The body is the row's button; the diff size and the menu stay separate parts after it. + expect(rowParts(element)).toBe('button:body(icon content) trailing menu') expect(within(element).getByText('Local changes · 2 files')).toBeTruthy() expect(within(element).getByText('+5')).toBeTruthy() fireEvent.click(within(element).getByRole('button', { name: 'Local changes · 2 files, 5 lines added, 1 lines deleted' })) diff --git a/packages/experimental/client-ui-forge/tests/panel-row-factory.client.tsx b/packages/experimental/client-ui-forge/tests/panel-row-factory.client.tsx deleted file mode 100644 index 462c1da5e7..0000000000 --- a/packages/experimental/client-ui-forge/tests/panel-row-factory.client.tsx +++ /dev/null @@ -1,44 +0,0 @@ -/** - * The Session panel's `conversation.session.panel.row` Factory as these - * suites render it: the row's parts in the row's order, its attributes on the - * row element, and its action as a button. ui-session-panel's own suite owns - * the row's geometry and interaction states. - */ -import type { ReactNode } from 'react' -import { vi } from 'vitest' -import type { PanelRowProps } from '@deepseek-ai/dsh-client-ui-session-panel/client' - -/** - * Render one row the way the Factory lays it out. - * @param props - the row's Factory input. - * @returns the row element. - */ -function PanelRowDouble({ - icon, children, trailing, menu, onActivate, actionLabel, detail, className, attributes, -}: PanelRowProps): ReactNode { - const body = ( - <> - - {children} - {detail !== undefined && {detail}} - - ) - return ( -
    - {onActivate === undefined ? {body} : } - {trailing} - {menu} -
    - ) -} - -/** - * A recording `renderFactorySlot` that renders panel rows and hands every other Factory to `other`. - * @param other - renders the other Factories the component under test uses. - * @returns the mock. - */ -export function renderPanelRows(other: (name: string, input: never) => ReactNode = () => null) { - return vi.fn((name: string, input: object): ReactNode => name === 'conversation.session.panel.row' - ? - : other(name, input as never)) -} diff --git a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts index 3528732eb2..486696310d 100644 --- a/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts +++ b/packages/extensions/cordis-client-runner/src/client/slot-catalog.ts @@ -2409,7 +2409,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ ], replaceRisk: 'none', example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.session.panel.environment.row\', () => ctx.slots.register(\n { name: \'conversation.session.panel.environment.row\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', - source: 'packages/client/ui-session-panel/src/client/slots.ts:57', + source: 'packages/client/ui-session-panel/src/client/slots.ts:44', }, { key: 'conversation.session.panel.indicator', @@ -2473,7 +2473,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ ], replaceRisk: 'none', example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.session.panel.indicator\', () => ctx.slots.register(\n { name: \'conversation.session.panel.indicator\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', - source: 'packages/client/ui-session-panel/src/client/slots.ts:50', + source: 'packages/client/ui-session-panel/src/client/slots.ts:37', }, { key: 'conversation.session.panel.section', @@ -2541,7 +2541,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ ], replaceRisk: 'none', example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.session.panel.section\', () => ctx.slots.register(\n { name: \'conversation.session.panel.section\', id: \'my-entry\', order: 100, label: \'My entry\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', - source: 'packages/client/ui-session-panel/src/client/slots.ts:35', + source: 'packages/client/ui-session-panel/src/client/slots.ts:22', }, { key: 'conversation.session.panel.section.actions', @@ -2591,7 +2591,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [ ], replaceRisk: 'shadows-shipped-ui', example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'conversation.session.panel.section.actions\', () => ctx.slots.register(\n { name: \'conversation.session.panel.section.actions\', key: \'\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}', - source: 'packages/client/ui-session-panel/src/client/slots.ts:41', + source: 'packages/client/ui-session-panel/src/client/slots.ts:28', }, { key: 'conversation.trajectory.images', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fce761d0c9..6b0ec29868 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5830,9 +5830,6 @@ importers: '@testing-library/react': specifier: ^16.3.3 version: 16.3.3(@testing-library/dom@10.4.2)(@types/react-dom@18.3.7(@types/react@18.3.31))(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - clsx: - specifier: ^2.0.0 - version: 2.1.1 react: specifier: ^18.2.0 version: 18.3.1 diff --git a/tsconfig.host.json b/tsconfig.host.json index ef566283e7..aac085d062 100644 --- a/tsconfig.host.json +++ b/tsconfig.host.json @@ -11,7 +11,7 @@ "snapshots/session/headless.snapshot.ts", "apps/web/tests/home-whale.e2e.ts", "apps/web/tests/sidebar-drawer.e2e.ts", - "apps/web/tests/session-panel-dock.e2e.ts", + "apps/web/tests/session-panel-layout.e2e.ts", "apps/web/tests/creation-recommendations.e2e.ts", "apps/web/tests/plugin-recommendations.e2e.ts", "apps/web/tests/japanese-plugin-metadata.e2e.ts",