diff --git a/packages/app/e2e/regression/new-session.spec.ts b/packages/app/e2e/regression/new-session.spec.ts index 7ac8f59b72d..b372d0e67b9 100644 --- a/packages/app/e2e/regression/new-session.spec.ts +++ b/packages/app/e2e/regression/new-session.spec.ts @@ -1,7 +1,7 @@ import { expect, test, type Locator, type Page } from "@playwright/test" import type { OpenCodeEvent, WorktreeDirectory } from "@opencode/client/promise" import { draftHref, expectPath, NO_PROVIDER, project, provider, seed, sessionHref, T0 } from "../utils/app" -import { mockOpenCodeServer, type MockAnswer } from "../utils/mock-server" +import { mockOpenCodeServer } from "../utils/mock-server" import { newSessionLocation, openDraft, openSession, openWorktreeDraft, type WorkspaceInput } from "../utils/workspace" const directory = "C:/OpenCode/WorkspacePending" @@ -37,7 +37,7 @@ const pendingDraft = { createdSessionTitle: "Created workspace session", } satisfies WorkspaceInput & { draftID: string } -const failFirstCreate = (_: unknown, attempt: number): MockAnswer | undefined => +const failFirstCreate: NonNullable = (_body, attempt) => attempt === 1 ? { status: 500, body: { message: "Session creation failed in the fixture" } } : undefined test.use({ @@ -179,7 +179,11 @@ test("a pending worktree session shows immediately, keeps its draft, and hands o const label = page.locator('[data-titlebar-tab-slot][data-active="true"] [data-titlebar-tab-title]') await expect(label).toHaveText("Session") const pending = await submitPending(page, mock) - const spinner = tabLink(page, pending.sessionID).locator('[data-component="session-progress-indicator-v2"]') + + const spinner = page.locator( + `[data-titlebar-tab-slot]:has(a[href="${sessionHref(pending.sessionID)}"]) [data-component="activity-ring"]`, + ) + await expect(spinner).toBeVisible() await expect(label).toHaveText("Session") @@ -276,9 +280,7 @@ test("the title and message stay stable through worktree creation", async ({ pag title: visible(title) ? title!.textContent : null, message: visible(document.querySelector('[data-component="user-message"]')), spinner: visible( - document.querySelector( - '[data-titlebar-tab-slot][data-active="true"] [data-component="session-progress-indicator-v2"]', - ), + document.querySelector('[data-titlebar-tab-slot][data-active="true"] [data-component="activity-ring"]'), ), draft: visible(editor) ? editor!.textContent : null, }) @@ -469,6 +471,7 @@ test("executes a selected slash command after creating its worktree", async ({ p }, ]) // The server owns command expansion; the client receives the expanded inbox item. + // SAFETY: the fixture event matches the generated OpenCodeEvent shape for its type. await mock.push([ { id: "evt_workspace_review", @@ -494,8 +497,10 @@ test("the location dialog lists every ready server's projects in one list and ta page, }) => { const apollo = "http://apollo.test:4096" + const entry = (id: string, directory: string, active: number) => project({ id, directory, time: { created: T0, updated: T0, active: T0 + active } }) + const remote = entry("proj_apollo_opencode", "/home/dax/opencode", 4) const files: string[] = [] page.on("request", (request) => { @@ -645,6 +650,7 @@ for (const row of [ (response) => new URL(response.url()).pathname === "/api/worktree" && response.request().method() === "GET", ) + // SAFETY: the fixture event matches the generated OpenCodeEvent shape for its type. await view.push([ { id: "evt_accent_inventory", @@ -657,6 +663,7 @@ for (const row of [ await expect(page).toHaveURL(url) await expect(view.editor).toHaveText("Inspect this fixture workspace.") await expectBackground(send, "icon-button-contrast") + // SAFETY: the fixture event matches the generated OpenCodeEvent shape for its type. await view.push([ { id: "evt_accent_running", @@ -674,6 +681,7 @@ for (const row of [ } function renamed(sessionID: string) { + // SAFETY: the fixture event matches the generated OpenCodeEvent shape for its type. return { id: "evt_generated_title", type: "session.renamed", diff --git a/packages/app/e2e/regression/tabs.spec.ts b/packages/app/e2e/regression/tabs.spec.ts index b4b01792016..e2e39458600 100644 --- a/packages/app/e2e/regression/tabs.spec.ts +++ b/packages/app/e2e/regression/tabs.spec.ts @@ -75,7 +75,8 @@ test("inactive session attention dots share the close control without marking th await page.goto(sessionHref(a.id)) const tabA = page.locator(`[data-titlebar-tab-slot]:has(a[href="${sessionHref(a.id)}"])`) const tabB = page.locator(`[data-titlebar-tab-slot]:has(a[href="${sessionHref(b.id)}"])`) - const dot = tabB.locator('[data-slot="tab-unread-dot"]') + const dot = tabB.locator('[data-mark="attention"]') + const status = tabB.locator('[data-slot="tab-status"]') const close = tabB.getByRole("button", { name: "Close tab", exact: true }) await expect(tabA.locator('[data-slot="tab-title"]')).toHaveText(a.title) await expect(tabB.locator('[data-slot="tab-title"]')).toHaveText(b.title) @@ -99,21 +100,21 @@ test("inactive session attention dots share the close control without marking th .toBeLessThan(1) await tabB.hover() - await expect(dot).toBeHidden() + await expect(status).toHaveCSS("opacity", "0") await expect(close).toHaveCSS("opacity", "1") await page.mouse.move(0, 0) await tabB.locator("[data-titlebar-tab-link]").focus() await page.keyboard.press("Tab") await expect(close).toBeFocused() - await expect(dot).toBeHidden() + await expect(status).toHaveCSS("opacity", "0") await expect(close).toHaveCSS("opacity", "1") await close.blur() - await expect(dot).toBeVisible() + await expect(status).toHaveCSS("opacity", "1") await tabB.locator("[data-titlebar-tab-link]").click() await expectPath(page, sessionHref(b.id)) await expect(tabB).toHaveAttribute("data-active", "true") - await expect(dot).toHaveCount(0) + await expect(dot).toBeHidden() await tabA.locator("[data-titlebar-tab-link]").click() await expectPath(page, sessionHref(a.id)) await page.mouse.move(0, 0) @@ -218,7 +219,7 @@ test("option arrows move to the previous or next tab, and with shift to the next await page.goto(sessionHref(a.id)) await page.mouse.move(0, 0) await expect( - page.locator(`[data-titlebar-tab-slot]:has(a[href="${sessionHref(c.id)}"]) [data-slot="tab-unread-dot"]`), + page.locator(`[data-titlebar-tab-slot]:has(a[href="${sessionHref(c.id)}"]) [data-mark="attention"]`), ).toBeVisible() await page.keyboard.press("Alt+ArrowDown") @@ -310,13 +311,13 @@ for (const row of [ await expect(tabA).toHaveAttribute("data-active", "true") await expect(tabA.locator('[data-slot="tab-close"]')).toBeVisible() await expect(tabB.locator('[data-slot="tab-close"]')).toBeVisible() - await expect(tabB.locator('[data-slot="tab-unread-dot"]')).toBeVisible() - await expect(tabB.locator('[data-slot="tab-unread-slot"]')).toHaveCSS("width", "20px") - await expect(tabB.locator('[data-slot="tab-unread-slot"]')).toHaveCSS("height", "20px") + await expect(tabB.locator('[data-mark="attention"]')).toBeVisible() + await expect(tabB.locator('[data-slot="tab-status"]')).toHaveCSS("width", "20px") + await expect(tabB.locator('[data-slot="tab-status"]')).toHaveCSS("height", "20px") await expect .poll(() => tabB.evaluate((element) => { - const dot = element.querySelector('[data-slot="tab-unread-slot"]')!.getBoundingClientRect() + const dot = element.querySelector('[data-slot="tab-status"]')!.getBoundingClientRect() const close = element.querySelector('[data-slot="tab-close"]')!.getBoundingClientRect() return dot.right <= close.left || dot.left >= close.right @@ -670,9 +671,9 @@ test("a remote tab stays busy while a child session runs", async ({ page }) => { const tabB = page.locator(`[data-titlebar-tab-slot]:has(a[href="${sessionHref(sessionB.id, REMOTE_SERVER)}"])`) const tabA = page.locator(`[data-titlebar-tab-slot]:has(a[href="${sessionHref(sessionA.id)}"])`) - await expect(tabB.locator('[data-component="session-progress-indicator-v2"]')).toBeVisible() + await expect(tabB.locator('[data-component="activity-ring"]')).toBeVisible() await expect(tabA.locator("[data-titlebar-tab-title]")).toHaveText(sessionA.title) - await expect(tabA.locator('[data-component="session-progress-indicator-v2"]')).toHaveCount(0) + await expect(tabA.locator('[data-component="activity-ring"]')).toBeHidden() }) test("inactive tabs stay busy while work waits in their inbox, and pulse on a new prompt, as in the TUI", async ({ @@ -703,11 +704,11 @@ test("inactive tabs stay busy while work waits in their inbox, and pulse on a ne }) const tab = (id: string) => page.locator(`[data-titlebar-tab-slot]:has(a[href="${sessionHref(id)}"])`) - const progress = '[data-component="session-progress-indicator-v2"]' + const progress = '[data-component="activity-ring"]' await expect(tab(b.id).locator(progress)).toBeVisible() await expect(tab(c.id).locator("[data-titlebar-tab-title]")).toHaveText(c.title) - await expect(tab(c.id).locator(progress)).toHaveCount(0) + await expect(tab(c.id).locator(progress)).toBeHidden() await expect(tab(c.id).locator('[data-slot="tab-prompt-pulse"]')).toHaveCount(0) // The pulse lasts one animation, so record that it appeared rather than racing its removal. await tab(c.id).evaluate((element) => { @@ -756,7 +757,7 @@ test("switching between busy sessions keeps the busy indicators and the activity await expectSessionTitle(page, a.title) const sidebar = page.locator('[data-slot="vertical-tabs-sidebar"]') - const indicators = sidebar.locator('[data-component="session-progress-indicator-v2"]') + const indicators = sidebar.locator('[data-component="activity-ring"]') const capsule = page.locator('[data-slot="session-activity-chip"]') await expect(indicators).toHaveCount(2) await expect(capsule).toHaveText("1 subagent") @@ -774,7 +775,7 @@ test("switching between busy sessions keeps the busy indicators and the activity record.setAttribute("data-test-capsule-missing", "") }).observe(document.body, { childList: true, subtree: true }) document - .querySelectorAll('[data-slot="vertical-tabs-sidebar"] [data-component="session-progress-indicator-v2"]') + .querySelectorAll('[data-slot="vertical-tabs-sidebar"] [data-component="activity-ring"]') .forEach((element) => element.setAttribute("data-test-before-switch", "")) }) @@ -813,7 +814,7 @@ test("selecting a tab with waiting work waits for its transcript instead of show }) const tabB = page.locator(`[data-titlebar-tab-slot]:has(a[href="${sessionHref(b.id)}"])`) // The inactive tab read its inbox, which materializes the pending steer as a transcript row. - await expect(tabB.locator('[data-component="session-progress-indicator-v2"]')).toBeVisible() + await expect(tabB.locator('[data-component="activity-ring"]')).toBeVisible() const transcript = await holdRoute(page, (url) => url.pathname === `/api/session/${b.id}/message`) await page.locator(`[data-titlebar-tab-link][href="${sessionHref(b.id)}"]`).click() diff --git a/packages/app/src/shell/layout/project-avatar-state.ts b/packages/app/src/shell/layout/project-avatar-state.ts index ff035af5e3e..52d2b017e86 100644 --- a/packages/app/src/shell/layout/project-avatar-state.ts +++ b/packages/app/src/shell/layout/project-avatar-state.ts @@ -49,7 +49,7 @@ export function useSessionTabAvatarState( return sessionBusy(data, sessionId()) }) - return { unread, loading } + return { unread, loading, attention: needsAttention } } // Pending permission and form requests anywhere in the session (or its family, for roots). diff --git a/packages/app/src/shell/titlebar/tab-nav.css b/packages/app/src/shell/titlebar/tab-nav.css index 448b53e15c2..e8427b1d563 100644 --- a/packages/app/src/shell/titlebar/tab-nav.css +++ b/packages/app/src/shell/titlebar/tab-nav.css @@ -9,8 +9,7 @@ justify-content: center; } -[data-titlebar-tab] :is([data-slot="tab-unread-dot"], [data-slot="tab-avatar-unread-dot"]) { - position: absolute; +[data-titlebar-tab] :is([data-slot="tab-status-dot"], [data-slot="tab-avatar-unread-dot"]) { width: 7px; height: 7px; border-radius: 9999px; @@ -22,29 +21,54 @@ position: relative; } +[data-titlebar-tab] :is([data-mark="attention"], [data-status="attention"] [data-slot="tab-avatar-unread-dot"]) { + background: var(--v2-state-fg-warning); +} + [data-titlebar-tab] [data-slot="tab-avatar-unread-dot"] { + position: absolute; display: none; inset-inline-end: -3px; top: -3px; } -[data-titlebar-tab] [data-slot="tab-unread-slot"] { +/* Status sits where the close button appears; marks and the hover swap change instantly. */ +[data-titlebar-tab] [data-slot="tab-status"] { position: absolute; inset-block: 0; inset-inline-end: 0; - display: flex; + display: grid; margin-block: auto; width: 20px; height: 20px; - align-items: center; - justify-content: center; + place-items: center; pointer-events: none; } +[data-titlebar-tab] [data-slot="tab-status"] > [data-mark] { + grid-area: 1 / 1; + display: none; +} + +[data-titlebar-tab][data-status="busy"] [data-mark="busy"], +[data-titlebar-tab][data-status="attention"] [data-mark="attention"], +[data-titlebar-tab][data-status="unread"] [data-mark="unread"] { + display: block; +} + +[data-titlebar-tab] [data-slot="tab-close"] > button { + transition: none; +} + +/* Every row, the active one included, shows the close button only on hover or keyboard focus. */ +[data-titlebar-tab]:is(:hover, :has(:focus-visible), [data-editing="true"]) [data-slot="tab-close"] > button { + opacity: 1; +} + @media (hover: hover) { [data-titlebar-tab]:not(:where([data-slot="mobile-tabs-drawer"] *)):is(:hover, :has(:focus-visible)) - [data-slot="tab-unread-slot"] { - display: none; + [data-slot="tab-status"] { + opacity: 0; } } @@ -116,8 +140,7 @@ --tab-overlay: var(--v2-overlay-simple-overlay-pressed); } -[data-titlebar-tab]:is(:hover, :has(:focus-visible), [data-state="pressed"], [data-unread="true"]) - [data-slot="tab-close"] { +[data-titlebar-tab]:is(:hover, :has(:focus-visible), [data-state="pressed"], [data-status]) [data-slot="tab-close"] { background: linear-gradient(var(--tab-overlay), var(--tab-overlay)), var(--tab-base); } @@ -197,9 +220,7 @@ } [data-titlebar-tab][data-title-overflow="true"]:not([data-editing="true"]) [data-slot="tab-link"], -[data-titlebar-tab]:is(:hover, :has(:focus-visible), [data-active="true"], [data-unread="true"]):not( - [data-editing="true"] - ) +[data-titlebar-tab]:is(:hover, :has(:focus-visible), [data-active="true"], [data-status]):not([data-editing="true"]) [data-slot="tab-link"] { --tab-title-fade-offset: calc(4px + var(--tab-link-inset, 0px)); -webkit-mask-image: linear-gradient( @@ -219,7 +240,7 @@ } [data-titlebar-tab][data-title-overflow="true"]:not([data-editing="true"]):dir(rtl) [data-slot="tab-link"], -[data-titlebar-tab]:is(:hover, :has(:focus-visible), [data-active="true"], [data-unread="true"]):not( +[data-titlebar-tab]:is(:hover, :has(:focus-visible), [data-active="true"], [data-status]):not( [data-editing="true"] ):dir(rtl) [data-slot="tab-link"] { @@ -239,9 +260,7 @@ ); } -[data-titlebar-tab]:is(:hover, :has(:focus-visible), [data-active="true"], [data-unread="true"]):not( - [data-editing="true"] - ) +[data-titlebar-tab]:is(:hover, :has(:focus-visible), [data-active="true"], [data-status]):not([data-editing="true"]) [data-slot="tab-link"] { --tab-title-fade-offset: calc(24px + var(--tab-link-inset, 0px)); } @@ -270,7 +289,7 @@ } @media (hover: none) { - [data-titlebar-tab] [data-slot="tab-unread-slot"] { + [data-titlebar-tab] [data-slot="tab-status"] { inset-inline-end: 20px; } @@ -302,7 +321,7 @@ --tab-title-fade-direction: to left; } - [data-titlebar-tab][data-unread="true"]:not([data-editing="true"]) [data-slot="tab-link"] { + [data-titlebar-tab][data-status]:not([data-editing="true"]) [data-slot="tab-link"] { --tab-title-fade-offset: calc(44px + var(--tab-link-inset, 0px)); } } @@ -312,7 +331,7 @@ :hover, :has(:focus-visible), [data-active="true"], - [data-unread="true"] + [data-status] ) [data-slot="tab-link"] { -webkit-mask-image: none; @@ -323,7 +342,7 @@ :hover, :has(:focus-visible), [data-active="true"], - [data-unread="true"] + [data-status] ) [data-titlebar-tab-title] { visibility: hidden; @@ -337,12 +356,13 @@ height: 6px; } - [data-titlebar-tab][data-unread="true"]:not([data-orientation="vertical"]) [data-slot="project-avatar-surface"] { + [data-titlebar-tab]:is([data-status="attention"], [data-status="unread"]):not([data-orientation="vertical"]) + [data-slot="project-avatar-surface"] { -webkit-mask-image: radial-gradient(circle 4.5px at 100% 0, transparent 4px, black 5px); mask-image: radial-gradient(circle 4.5px at 100% 0, transparent 4px, black 5px); } - [data-titlebar-tab][data-unread="true"]:not([data-orientation="vertical"]):dir(rtl) + [data-titlebar-tab]:is([data-status="attention"], [data-status="unread"]):not([data-orientation="vertical"]):dir(rtl) [data-slot="project-avatar-surface"] { -webkit-mask-image: radial-gradient(circle 4.5px at 0 0, transparent 4px, black 5px); mask-image: radial-gradient(circle 4.5px at 0 0, transparent 4px, black 5px); @@ -364,12 +384,15 @@ display: none; } - [data-titlebar-tab]:not([data-orientation="vertical"]):not([data-active="true"]) [data-slot="tab-close"] { + [data-titlebar-tab]:not([data-orientation="vertical"]):not([data-active="true"]):not([data-status="busy"]) + [data-slot="tab-close"] { display: none; } @media (hover: hover) { - [data-titlebar-tab]:not([data-orientation="vertical"]):not(:hover):not(:has(:focus-visible)) + [data-titlebar-tab]:not([data-orientation="vertical"]):not([data-status="busy"]):not(:hover):not( + :has(:focus-visible) + ) [data-slot="tab-close"] { display: none; } @@ -380,6 +403,22 @@ left: 50%; transform: translateX(-50%); } + + /* Icon-only tabs have no room on the right, so a busy one spins over its icon. */ + [data-titlebar-tab][data-status="busy"]:not([data-orientation="vertical"]):not([data-active="true"]) + [data-slot="tab-close"] + > button { + visibility: hidden; + } + + [data-titlebar-tab][data-status="busy"]:not([data-orientation="vertical"]):not([data-active="true"]) + [data-slot="tab-status"] { + opacity: 1; + } + + [data-titlebar-tab][data-status="busy"]:not([data-orientation="vertical"]) [data-slot="project-avatar-slot"] { + visibility: hidden; + } } /* A prompt that arrives in a background tab rings it once, like the TUI's prompt pulse. */ diff --git a/packages/app/src/shell/titlebar/tab-nav.tsx b/packages/app/src/shell/titlebar/tab-nav.tsx index 00905063989..738fcde2ed2 100644 --- a/packages/app/src/shell/titlebar/tab-nav.tsx +++ b/packages/app/src/shell/titlebar/tab-nav.tsx @@ -3,6 +3,7 @@ import { createStore } from "solid-js/store" import { Predicate } from "effect" import { makeEventListener } from "@solid-primitives/event-listener" import { createResizeObserver } from "@solid-primitives/resize-observer" +import { ActivityRing } from "@opencode/ui/activity-ring" import { IconButton } from "@opencode/ui/icon-button" import { Icon } from "@opencode/ui/icon" import { Menu } from "@opencode/ui/menu" @@ -11,7 +12,6 @@ import { useLanguage } from "@/runtime/i18n/language" import { ServerConnection, useServers } from "@/runtime/server/registry" import { displayName } from "@opencode/ui/project-avatar" import { SessionTabAvatarView } from "@/shell/layout/session-tab-avatar" -import { SessionProgressIndicatorV2 } from "@opencode/session-ui/v2/session-progress-indicator-v2" import type { SessionInfo } from "@opencode/client/promise" import { sessionTabTitle } from "./tab-title" import { TabPreviewPopover } from "./tab-popover" @@ -27,6 +27,7 @@ export function TabNavItem(props: { session: SessionInfo | undefined preparing: boolean unread: boolean + attention: boolean loading: boolean fallbackTitle?: string fallbackDirectory?: string @@ -58,7 +59,18 @@ export function TabNavItem(props: { const servers = useServers() const serverCtx = useServerCtx(() => servers.list.find((item) => ServerConnection.key(item) === props.server)) - const unread = () => !!props.session && !props.active && props.unread + // The project icon stays put; status shows where the close button appears on hover. + const status = () => { + if (props.preparing || props.loading) return "busy" + + if (!props.session || props.active) return + + if (props.attention) return "attention" + + if (props.unread) return "unread" + } + + const dotted = () => status() === "attention" || status() === "unread" const project = createMemo(() => { const session = props.session @@ -238,7 +250,7 @@ export function TabNavItem(props: { class="group relative flex h-7 w-full min-w-0 select-none flex-row items-center gap-1.5 overflow-hidden whitespace-nowrap rounded-[6px] px-1.5 [container-type:inline-size]" classList={{ invisible: props.hidden }} data-active={props.active} - data-unread={unread()} + data-status={status()} data-dragging={props.dragging} data-state={props.active || props.pressed ? "pressed" : undefined} onMouseDown={(event) => { @@ -291,47 +303,14 @@ export function TabNavItem(props: { > - } - > - - + @@ -378,15 +357,15 @@ export function TabNavItem(props: {
- - +