Skip to content

Commit ad53e39

Browse files
fix(app): group nested tabs and show full session path (anomalyco#51064)
Co-authored-by: Brendonovich <14191578+Brendonovich@users.noreply.github.com>
1 parent 3ddfc15 commit ad53e39

4 files changed

Lines changed: 201 additions & 59 deletions

File tree

‎packages/app/e2e/regression/subagent-child-navigation.spec.ts‎

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ const directory = "C:/OpenCode/SubagentNavigation"
88
const projectID = "proj_subagent_navigation"
99
const parentID = "ses_subagent_parent"
1010
const childID = "ses_subagent_child"
11+
const grandchildID = "ses_subagent_grandchild"
12+
const greatGrandchildID = "ses_subagent_great_grandchild"
1113
const parentTitle = "Parent session"
1214
const childTitle = "Subagent child session"
15+
const grandchildTitle = "Nested subagent session"
16+
const greatGrandchildTitle =
17+
"Deep research subagent session investigating a very long chain of agent registry failures and navigation breadcrumbs"
1318
// Child session pages derive their heading from the task part that spawned them.
1419
const taskDescription = "Inspect child navigation"
1520

@@ -25,6 +30,60 @@ test("navigates to a subagent child session missing from the session list", asyn
2530
await expect(page.getByRole("button", { name: "Toggle review", exact: true })).toBeVisible()
2631
})
2732

33+
test("opens a directly linked nested subagent in its root session tab", async ({ page }) => {
34+
await setup(page, undefined, 1)
35+
await page.goto(sessionHref(grandchildID), { waitUntil: "domcontentloaded" })
36+
37+
await expect(page.locator('[data-slot="session-title-parent"]')).toHaveText(childTitle)
38+
await expect(page.locator('[data-slot="session-title-child"]')).toHaveText(grandchildTitle)
39+
const tabs = page.locator('[data-slot="titlebar-tabs"] [data-titlebar-tab-slot]')
40+
await expect(tabs.locator(`a[href="${sessionHref(grandchildID)}"]`)).toHaveCount(1)
41+
await expect(tabs).toHaveCount(1)
42+
await expect(tabs.locator('[data-slot="tab-title"]')).toHaveText(parentTitle)
43+
})
44+
45+
test("shows the full ancestor path and navigates to an earlier subagent", async ({ page }) => {
46+
await setup(page, undefined, 2)
47+
await page.goto(sessionHref(greatGrandchildID), { waitUntil: "domcontentloaded" })
48+
49+
await expect(page.locator("[data-timeline-virtual-content]")).toBeAttached()
50+
const header = page.locator("[data-session-title]")
51+
await expect(header.locator('[data-slot="session-title-ancestor"]')).toHaveText([parentTitle, childTitle])
52+
await expect(header.locator('[data-slot="session-title-parent"]')).toHaveText(grandchildTitle)
53+
await expect(header.getByRole("heading", { name: greatGrandchildTitle })).toBeVisible()
54+
55+
await header.getByRole("button", { name: childTitle, exact: true }).click()
56+
await expect(page).toHaveURL(sessionHref(childID))
57+
await expect(page.locator("[data-session-title]").getByRole("heading", { name: childTitle })).toBeVisible()
58+
await expect(page.locator('[data-slot="titlebar-tabs"] [data-titlebar-tab-slot]')).toHaveCount(1)
59+
})
60+
61+
test("keeps the active nested session visible in a narrow desktop header", async ({ page }) => {
62+
await page.setViewportSize({ width: 820, height: 720 })
63+
await setup(page, undefined, 2)
64+
await page.goto(sessionHref(greatGrandchildID), { waitUntil: "domcontentloaded" })
65+
66+
const header = page.locator("[data-session-title]")
67+
const heading = header.getByRole("heading", { name: greatGrandchildTitle })
68+
const separator = header.locator('[data-slot="session-title-ancestors"] + [data-slot="session-title-separator"]')
69+
await expect(header.locator('[data-slot="session-title-ancestor"]')).toHaveText([parentTitle, childTitle])
70+
await expect(heading).toBeInViewport()
71+
await expect(separator).toBeInViewport()
72+
const bounds = await heading.boundingBox()
73+
expect(bounds).not.toBeNull()
74+
expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(820)
75+
76+
await page.evaluate(() => document.documentElement.setAttribute("dir", "rtl"))
77+
await expect(heading).toBeInViewport()
78+
await expect(separator).toBeInViewport()
79+
80+
const root = header.locator(`[data-slot="session-title-ancestor"][data-session-id="${parentID}"]`)
81+
await root.focus()
82+
await expect(root).toBeFocused()
83+
await root.press("Enter")
84+
await expect(page).toHaveURL(sessionHref(parentID))
85+
})
86+
2887
test("returns to the parent session with Escape", async ({ page }) => {
2988
await setup(page)
3089
await openChildFromParent(page)
@@ -144,7 +203,7 @@ test("shows the not found fallback when the viewed session is deleted", async ({
144203
await expect(page.getByRole("heading", { name: taskDescription })).toHaveCount(0)
145204
})
146205

147-
async function setup(page: Page, events?: () => OpenCodeEvent[]) {
206+
async function setup(page: Page, events?: () => OpenCodeEvent[], nestedDepth: 0 | 1 | 2 = 0) {
148207
await mockOpenCodeServer(page, {
149208
directory,
150209
project: {
@@ -168,7 +227,14 @@ async function setup(page: Page, events?: () => OpenCodeEvent[]) {
168227
connected: ["opencode"],
169228
default: { providerID: "opencode", modelID: "claude-opus-4-6" },
170229
},
171-
sessions: [session(parentID, parentTitle, 1700000000000), childSession()],
230+
sessions: [
231+
session(parentID, parentTitle, 1700000000000),
232+
childSession(),
233+
...(nestedDepth >= 1 ? [session(grandchildID, grandchildTitle, 1700000002000, { parentID: childID })] : []),
234+
...(nestedDepth >= 2
235+
? [session(greatGrandchildID, greatGrandchildTitle, 1700000003000, { parentID: grandchildID })]
236+
: []),
237+
],
172238
pageMessages: (sessionID) => ({ items: sessionID === parentID ? parentMessages() : [] }),
173239
events,
174240
eventRetry: events ? 16 : undefined,

‎packages/app/src/session/session-identity-header.tsx‎

Lines changed: 96 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ProjectAvatar } from "@opencode/ui/project-avatar"
66
import { Tooltip } from "@opencode/ui/tooltip"
77
import { createResizeObserver } from "@solid-primitives/resize-observer"
88
import { useNavigate } from "@solidjs/router"
9-
import { createMemo, Show, type ParentProps } from "solid-js"
9+
import { createMemo, For, Show, type ParentProps } from "solid-js"
1010
import { createStore } from "solid-js/store"
1111
import { useServer } from "@/runtime/server/current"
1212
import { ServerConnection } from "@/runtime/server/registry"
@@ -191,12 +191,96 @@ export function SessionProjectMenu(props: {
191191
)
192192
}
193193

194+
export function SessionAncestorTrail(props: {
195+
sessionID: string
196+
parentID: string
197+
parentTitle?: string
198+
trailing: boolean
199+
}) {
200+
const server = useServer()
201+
const tabs = useTabs()
202+
const navigate = useNavigate()
203+
const language = useLanguage()
204+
const ancestors = createMemo(() => {
205+
const path: { id: string; title: string; direct: boolean }[] = []
206+
const seen = new Set([props.sessionID])
207+
let id: string | undefined = props.parentID
208+
while (id && !seen.has(id)) {
209+
seen.add(id)
210+
const info = server.ctx.data.session.get(id)
211+
path.unshift({
212+
id,
213+
title:
214+
sessionTitle(info?.title ?? (id === props.parentID ? props.parentTitle : undefined)) ??
215+
language.t("session.tab.session"),
216+
direct: id === props.parentID,
217+
})
218+
id = info?.parentID
219+
}
220+
return path
221+
})
222+
const open = (id: string) => {
223+
const tab = tabs.store.find(
224+
(item) =>
225+
item.type === "session" &&
226+
item.server === server.key &&
227+
(item.sessionId === props.sessionID || item.routeSessionId === props.sessionID),
228+
)
229+
if (tab?.type === "session") tabs.rememberSessionRoute(tab, id, server.ctx.data.session.get(id)?.parentID)
230+
navigate(sessionHref(server.key, id))
231+
}
232+
233+
return (
234+
<div class="flex min-w-0 max-w-full items-center">
235+
<div
236+
data-slot="session-title-ancestors"
237+
class="flex min-w-0 items-center overflow-x-auto whitespace-nowrap [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
238+
>
239+
<For each={ancestors()}>
240+
{(ancestor, index) => (
241+
<>
242+
<button
243+
type="button"
244+
data-slot={ancestor.direct ? "session-title-parent" : "session-title-ancestor"}
245+
data-session-id={ancestor.id}
246+
title={ancestor.title}
247+
dir="auto"
248+
class="max-w-[min(200px,40vw)] shrink-0 truncate pl-2 text-[13px] font-[530] leading-4 tracking-[-0.04px] text-v2-text-text-faint transition-colors hover:text-v2-text-text-muted"
249+
onClick={() => open(ancestor.id)}
250+
>
251+
{ancestor.title}
252+
</button>
253+
<Show when={index() < ancestors().length - 1}>
254+
<span
255+
data-slot="session-title-separator"
256+
class="-translate-y-[0.5px] shrink-0 pl-2 pr-1 text-[11px] font-medium text-v2-text-text-faint"
257+
aria-hidden="true"
258+
>
259+
/
260+
</span>
261+
</Show>
262+
</>
263+
)}
264+
</For>
265+
</div>
266+
<Show when={props.trailing}>
267+
<span
268+
data-slot="session-title-separator"
269+
class="-translate-y-[0.5px] shrink-0 pl-2 pr-1 text-[11px] font-medium text-v2-text-text-faint"
270+
aria-hidden="true"
271+
>
272+
/
273+
</span>
274+
</Show>
275+
</div>
276+
)
277+
}
278+
194279
export function SessionIdentityHeader(props: { sessionID: string; session?: SessionInfo }) {
195280
const server = useServer()
196281
const tabs = useTabs()
197282
const language = useLanguage()
198283
const pending = createMemo(() => tabs.pendingSession(server.key, props.sessionID))
199-
const navigate = useNavigate()
200284
const tab = createMemo(() =>
201285
tabs.store.find(
202286
(item) =>
@@ -250,53 +334,30 @@ export function SessionIdentityHeader(props: { sessionID: string; session?: Sess
250334
)
251335
})
252336
const workspaceSession = createMemo(() => !!pending() || isWorkspaceDirectory(project(), directory() ?? ""))
253-
const navigateParent = () => {
254-
const id = parentID()
255-
const current = tab()
256-
if (!id || current?.type !== "session") return
257-
tabs.rememberSessionRoute(current, id, parent()?.parentID)
258-
navigate(sessionHref(server.key, id))
259-
}
260-
261337
return (
262338
<Show when={title() || parentTitle()}>
263339
<SessionTitleHeader>
264340
<div class="flex h-12 w-full items-center justify-between gap-2">
265341
<div class="flex min-w-0 flex-1 items-center gap-1">
266342
<div class="flex min-w-0 w-full flex-1 items-center gap-0.5">
267-
<SessionProjectMenu
268-
project={project()}
269-
directory={directory()}
270-
workspace={workspaceSession()}
271-
/>
272-
<Show when={parentTitle()}>
273-
{(value) => (
274-
<button
275-
type="button"
276-
data-slot="session-title-parent"
277-
dir="auto"
278-
class="min-w-0 max-w-[40%] truncate pl-2 text-[13px] font-[530] leading-4 tracking-[-0.04px] text-v2-text-text-faint transition-colors hover:text-v2-text-text-muted"
279-
onClick={navigateParent}
280-
>
281-
{value()}
282-
</button>
343+
<SessionProjectMenu project={project()} directory={directory()} workspace={workspaceSession()} />
344+
<Show when={parentID()}>
345+
{(id) => (
346+
<SessionAncestorTrail
347+
sessionID={props.sessionID}
348+
parentID={id()}
349+
parentTitle={parentTitle()}
350+
trailing={!!title()}
351+
/>
283352
)}
284353
</Show>
285-
<Show when={parentTitle() && title()}>
286-
<span
287-
data-slot="session-title-separator"
288-
class="-translate-y-[0.5px] pl-2 pr-1 text-[11px] font-medium text-v2-text-text-faint"
289-
aria-hidden="true"
290-
>
291-
/
292-
</span>
293-
</Show>
294354
<Show when={title()}>
295355
{(value) => (
296356
<h1
297357
data-slot={parentID() ? "session-title-child" : undefined}
298358
dir="auto"
299359
class="w-fit truncate rounded-[6px] px-1 py-1 text-[13px] font-[530] leading-4 tracking-[-0.04px] text-v2-text-text-base"
360+
classList={{ "max-w-[45%] shrink-0": !!parentID() }}
300361
>
301362
{value()}
302363
</h1>

‎packages/app/src/session/timeline/message-timeline.tsx‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { containsDirectory, isWorkspaceDirectory } from "@/workspaces/paths"
3434
import { projectForSession } from "@/shell/layout/helpers"
3535
import { parseCommentNote, readPromptPresentation } from "@/composer/comment-note"
3636
import { useCommand } from "@/shell/commands/command"
37-
import { SessionProjectMenu, SessionTitleHeader } from "../session-identity-header"
37+
import { SessionAncestorTrail, SessionProjectMenu, SessionTitleHeader } from "../session-identity-header"
3838
import { SessionHeaderSpacer } from "@/session/header/session-header"
3939
import type { BackgroundTask } from "../summary/background"
4040

@@ -413,21 +413,14 @@ function MessageTimelineView(
413413
workspace={workspaceSession()}
414414
/>
415415
<Show when={parentID()}>
416-
<button
417-
type="button"
418-
data-slot="session-title-parent"
419-
class="min-w-0 max-w-[40%] truncate pl-2 text-[13px] font-[530] leading-4 tracking-[-0.04px] text-v2-text-text-faint transition-colors hover:text-v2-text-text-muted"
420-
onClick={props.action.navigateParent}
421-
>
422-
{parentTitle()}
423-
</button>
424-
<span
425-
data-slot="session-title-separator"
426-
class="-translate-y-[0.5px] pl-2 pr-1 text-[11px] font-medium text-v2-text-text-faint"
427-
aria-hidden="true"
428-
>
429-
/
430-
</span>
416+
{(id) => (
417+
<SessionAncestorTrail
418+
sessionID={sessionID() ?? ""}
419+
parentID={id()}
420+
parentTitle={parentTitle()}
421+
trailing={!!(childTitle() || title.editing)}
422+
/>
423+
)}
431424
</Show>
432425
<Show when={childTitle() || title.editing}>
433426
<Show
@@ -436,6 +429,7 @@ function MessageTimelineView(
436429
<h1
437430
data-slot="session-title-child"
438431
class="truncate text-[13px] font-[530] leading-4 tracking-[-0.04px] text-v2-text-text-base w-fit rounded-[6px] px-1 py-1 hover:bg-v2-overlay-simple-overlay-hover"
432+
classList={{ "max-w-[45%] shrink-0": !!parentID() }}
439433
onClick={openTitleEditor}
440434
>
441435
{childTitle()}
@@ -451,6 +445,7 @@ function MessageTimelineView(
451445
value={title.draft}
452446
disabled={props.pending.rename()}
453447
class="block text-[13px] font-[530] leading-4 tracking-[-0.04px] text-v2-text-text-base field-sizing-content rounded-[6px] px-1 py-1"
448+
classList={{ "max-w-[45%] shrink-0": !!parentID() }}
454449
style={{
455450
"--inline-input-shadow": "none",
456451
"text-align": "start",

‎packages/app/src/shell/titlebar/titlebar.tsx‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { projectForSession } from "@/shell/layout/helpers"
3333
import { useSettingsDialog } from "@/settings/command"
3434
import { updaterAction } from "@/shell/updates/action"
3535
import type { UpdaterState } from "@/shell/updates/types"
36+
import { rootSession } from "@/shell/routes/session"
3637
import devIcon from "../../../../desktop/icons/dev/64x64.png"
3738
import betaIcon from "../../../../desktop/icons/beta/64x64.png"
3839

@@ -185,15 +186,31 @@ export function Titlebar(props: {
185186
const route = layout.route()
186187
return route.type === "session" && !!tabs.pendingSession(route.server, route.sessionId)
187188
})
188-
const [loadedSession] = createResource(
189+
const [resolvedSession] = createResource(
189190
() => {
190191
const route = layout.route()
191192
if (route.type !== "session") return undefined
192193
if (preparing()) return undefined
193194
const conn = global.servers.list().find((item) => ServerConnection.key(item) === route.server)
194195
return conn ? { route, ctx: global.ensureServerCtx(conn) } : undefined
195196
},
196-
({ route, ctx }) => ctx.sdk.api.session.get({ sessionID: route.sessionId }).catch(() => {}),
197+
async ({ route, ctx }) => {
198+
const info = await ctx.sdk.api.session
199+
.get({ sessionID: route.sessionId })
200+
.catch(() => ctx.data.session.get(route.sessionId))
201+
if (!info) return
202+
ctx.data.session.remember(info)
203+
const rootID = await rootSession(info, async (id) => {
204+
const cached = ctx.data.session.get(id)
205+
if (cached) return cached
206+
const ancestor = await ctx.sdk.api.session.get({ sessionID: id })
207+
ctx.data.session.remember(ancestor)
208+
return ancestor
209+
})
210+
.then((root) => root.id)
211+
.catch(() => ctx.data.session.root(info.id))
212+
return { info, rootID }
213+
},
197214
)
198215
const session = createMemo(() => {
199216
const route = layout.route()
@@ -202,8 +219,8 @@ export function Titlebar(props: {
202219
const conn = global.servers.list().find((item) => ServerConnection.key(item) === route.server)
203220
const cached = conn ? global.ensureServerCtx(conn).data.session.get(route.sessionId) : undefined
204221
if (cached) return cached
205-
const loaded = loadedSession()
206-
return loaded?.id === route.sessionId ? loaded : undefined
222+
const resolved = resolvedSession()
223+
return resolved?.info.id === route.sessionId ? resolved.info : undefined
207224
})
208225

209226
const matchRoute = (route: LayoutRoute) => {
@@ -221,7 +238,8 @@ export function Titlebar(props: {
221238
if (main) return main
222239
const s = session()
223240
if (s?.parentID) {
224-
const parentID = s.parentID
241+
const resolved = resolvedSession()
242+
const parentID = resolved?.info.id === s.id ? resolved.rootID : s.parentID
225243
const parent = tabsStore.find(
226244
(item) => item.type === "session" && item.server === route.server && item.sessionId === parentID,
227245
)
@@ -256,7 +274,9 @@ export function Titlebar(props: {
256274
}
257275
const s = session()
258276
if (!s) return
259-
const sessionId = s.parentID ?? s.id
277+
const resolved = resolvedSession()
278+
if (s.parentID && resolved?.info.id !== s.id) return
279+
const sessionId = resolved?.info.id === s.id ? resolved.rootID : s.id
260280
const next = { server: route.server, sessionId }
261281
tabsStoreActions.addSessionTab(next)
262282
}

0 commit comments

Comments
 (0)