Skip to content

Commit d724833

Browse files
Techno911claude
andcommitted
feat: open every new thread beside the focused pane, never over it
The project plus button opened the composer in a new pane, but ten other entry points still replaced the focused pane, so starting a thread from the sidebar button, the keyboard, the palette, a plugin, a fork, or a freshly created project closed whatever the user was watching. - `useOpenNewThreadPane` is the single way to start a thread: it sets the compose project, keeps the location state, and opens the composer through `openPaneContentInSplit`, so the focused pane survives and the composer lands to its right. Compact viewports keep the single-page behavior. - Every creating entry point now routes through it: the sidebar New thread button, the `thread.new` command (shortcut and palette), the project, section and Threads plus buttons, a new thread in an existing worktree, the plugin SDK `toCompose`, the plugin sidebar `openNewThread`, the skill library (edit, create, fork), the plugin editor, the custom palette prompt, forking a message, and quick project creation. - `useOpenNewThreadPane.test.ts` fails when a new file navigates to the compose route on its own, so the next entry point cannot skip the hook. Redirect-after-delete callers stay on an explicit list. Verified in a dev instance with Playwright: with a thread open, the sidebar button and the shortcut both leave it in place and add the composer pane to the right; the automation edit route still replaces its own history entry. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 69e3d53 commit d724833

15 files changed

Lines changed: 176 additions & 116 deletions

‎apps/app/src/components/layout/AppLayout.tsx‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ import { splitLayoutAtom } from "@/lib/split-layout/atoms";
111111
import { findPaneByThread } from "@/lib/split-layout";
112112
import { applyThreadOpenToLayout } from "@/views/thread-detail/splitThreadNavigation";
113113
import { useAppSettingsRouteMemory } from "@/hooks/useAppSettingsRouteMemory";
114-
import { useSetRootComposeProjectId } from "@/lib/root-compose-selection";
114+
import { useOpenNewThreadPane } from "@/hooks/useOpenNewThreadPane";
115115

116116
const SIDEBAR_WIDTH_KEY = "bb.sidebar.width";
117117
const SIDEBAR_OPEN_KEY = "bb.sidebar.open";
@@ -442,7 +442,7 @@ export function AppLayout({ children }: AppLayoutProps) {
442442
toolsBackRoutePath,
443443
toolsRoutePath,
444444
} = useAppSettingsRouteMemory();
445-
const setRootComposeProjectId = useSetRootComposeProjectId();
445+
const openNewThreadPane = useOpenNewThreadPane();
446446
useEffect(
447447
() =>
448448
wsManager.onThreadOpen((signal) => {
@@ -468,12 +468,7 @@ export function AppLayout({ children }: AppLayoutProps) {
468468
[isCompactViewport, navigate, store],
469469
);
470470
useAppCommandHandler("thread.new", () => {
471-
if (projectId !== undefined) {
472-
setRootComposeProjectId(projectId);
473-
}
474-
void navigate(getRootComposeRoutePath(), {
475-
state: { focusPrompt: true },
476-
});
471+
openNewThreadPane(projectId === undefined ? {} : { projectId });
477472
return true;
478473
});
479474
useAppCommandHandler("settings.open", () => {

‎apps/app/src/components/plugin/PluginsOverview.tsx‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ import {
3030
} from "@/components/plugin/plugin-provenance";
3131
import { PLUGINS_INSTALLED_DESCRIPTION } from "@/components/plugin/plugins-collection-copy";
3232
import { usePluginList } from "@/hooks/queries/plugin-settings-queries";
33-
import {
34-
getPluginDetailRoutePath,
35-
getRootComposeRoutePath,
36-
} from "@/lib/route-paths";
33+
import { getPluginDetailRoutePath } from "@/lib/route-paths";
34+
import { useOpenNewThreadPane } from "@/hooks/useOpenNewThreadPane";
3735

3836
type PluginsCollectionMode = "installed" | "browse";
3937

@@ -44,6 +42,7 @@ function modeFromSearchParams(value: string | null): PluginsCollectionMode {
4442

4543
export function PluginsOverview() {
4644
const navigate = useNavigate();
45+
const openNewThreadPane = useOpenNewThreadPane();
4746
const [searchParams] = useSearchParams();
4847
const listQuery = usePluginList({ enabled: true });
4948
const plugins = useMemo(
@@ -133,9 +132,8 @@ export function PluginsOverview() {
133132
});
134133

135134
const startCreatePlugin = (prompt?: string) => {
136-
navigate(getRootComposeRoutePath(), {
135+
openNewThreadPane({
137136
state: {
138-
focusPrompt: true,
139137
initialPrompt: prompt ?? CREATE_PLUGIN_PROMPT,
140138
replaceInitialPrompt: prompt !== undefined,
141139
},

‎apps/app/src/components/sidebar/AppSidebar.tsx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
MACOS_WINDOW_DRAG_CLASS,
3131
shouldUseMacosDesktopChrome,
3232
} from "@/lib/bb-desktop";
33-
import { getRootComposeRoutePath, getThreadRoutePath } from "@/lib/route-paths";
33+
import { getThreadRoutePath } from "@/lib/route-paths";
3434
import { usePaneContentSplitDrag } from "./usePaneContentSplitDrag";
3535
import { openUrlInExternalBrowser } from "@/lib/url-open-routing";
3636
import {
@@ -49,6 +49,7 @@ import {
4949
useIndexedAppCommandHandlers,
5050
} from "@/components/commands/AppCommandProvider";
5151
import { useRouteState } from "@/hooks/useRouteState";
52+
import { useOpenNewThreadPane } from "@/hooks/useOpenNewThreadPane";
5253

5354
const NEW_THREAD_PANE_CONTENT = { kind: "new-thread" } as const;
5455

@@ -76,6 +77,7 @@ export function AppSidebar({
7677
mobileHosted,
7778
}: AppSidebarProps) {
7879
const quickCreateProject = useQuickCreateProjectController();
80+
const openNewThreadPane = useOpenNewThreadPane();
7981
const threadListReplacement = useThreadListReplacement();
8082
const { threadId: activeThreadId } = useRouteState();
8183
const navigate = useNavigate();
@@ -102,10 +104,8 @@ export function AppSidebar({
102104

103105
const handleNewChat = useCallback(() => {
104106
closeOnMobile();
105-
void navigate(getRootComposeRoutePath(), {
106-
state: { focusPrompt: true },
107-
});
108-
}, [closeOnMobile, navigate]);
107+
openNewThreadPane();
108+
}, [closeOnMobile, openNewThreadPane]);
109109

110110
const showThreadShortcuts = useCallback(() => {
111111
const targets = getSidebarThreadShortcutTargets(sidebarRef.current);

‎apps/app/src/components/sidebar/ProjectList.tsx‎

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import {
88
type PointerEventHandler,
99
type ReactNode,
1010
} from "react";
11-
import { useNavigate } from "react-router-dom";
12-
import { useAtom, useAtomValue, useSetAtom, useStore } from "jotai";
11+
import { useAtom, useAtomValue, useSetAtom } from "jotai";
1312
import type {
1413
ProjectResponse,
1514
ThreadSectionResponse,
@@ -41,15 +40,10 @@ import { useHosts, usePrimaryHost } from "@/hooks/queries/host-queries";
4140
import { useDialogState } from "@/hooks/useDialogState";
4241
import { usePromptDraftInputThreadIds } from "@/hooks/usePromptDraftStorage";
4342
import { getCollapsedChildActivity } from "@bb/client-core";
44-
import { getRootComposeRoutePath } from "@/lib/route-paths";
45-
import { openPaneContentInSplit } from "@/lib/split-layout/openPaneContentInSplit";
46-
import { useIsCompactViewport } from "@bb/shared-ui/hooks/use-compact-viewport";
47-
48-
const NEW_THREAD_PANE_CONTENT = { kind: "new-thread" } as const;
43+
import { useOpenNewThreadPane } from "@/hooks/useOpenNewThreadPane";
4944
import { getThreadDisplayTitle } from "@/lib/thread-title";
5045
import { getMutationErrorMessage } from "@/lib/mutation-errors";
5146
import { BbHttpError } from "@bb/sdk/browser";
52-
import { useSetRootComposeProjectId } from "@/lib/root-compose-selection";
5347
import { cn } from "@bb/shared-ui/lib/utils";
5448
import { Button } from "@bb/shared-ui/button";
5549
import { AppCommandShortcutHint } from "@/components/commands/AppCommandShortcutHint";
@@ -1519,10 +1513,7 @@ function ProjectListComponent({
15191513
onProjectSelect,
15201514
isCreatingProject = false,
15211515
}: ProjectListProps) {
1522-
const navigate = useNavigate();
1523-
const store = useStore();
1524-
const isCompactViewport = useIsCompactViewport();
1525-
const setRootComposeProjectId = useSetRootComposeProjectId();
1516+
const openNewThreadPane = useOpenNewThreadPane();
15261517
const sidebarNavigationQuery = useSidebarNavigation();
15271518
const sidebarNavigation = sidebarNavigationQuery.data;
15281519
const sections = sidebarNavigation?.sections ?? EMPTY_SECTION_DEFINITIONS;
@@ -1594,23 +1585,13 @@ function ProjectListComponent({
15941585
);
15951586
const openRootComposeForProject = useCallback(
15961587
(projectId: string, sectionId?: string) => {
1597-
setRootComposeProjectId(projectId);
15981588
onProjectSelect?.();
1599-
const state = {
1600-
focusPrompt: true,
1601-
...(sectionId ? { sectionId } : {}),
1602-
};
1603-
openPaneContentInSplit({
1604-
store,
1605-
navigate: (route, options) => {
1606-
navigate(route, { ...options, state });
1607-
},
1608-
content: NEW_THREAD_PANE_CONTENT,
1609-
route: getRootComposeRoutePath(),
1610-
enabled: !isCompactViewport,
1589+
openNewThreadPane({
1590+
projectId,
1591+
...(sectionId ? { state: { sectionId } } : {}),
16111592
});
16121593
},
1613-
[isCompactViewport, navigate, onProjectSelect, setRootComposeProjectId, store],
1594+
[onProjectSelect, openNewThreadPane],
16141595
);
16151596
const handleCreateProjectThread = useCallback(
16161597
(projectId: string) => {

‎apps/app/src/components/tools/SkillsLibrary.tsx‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ import type { RegistryRanking, RegistrySkill } from "@/lib/skills-registry";
4141
import {
4242
getRegistrySkillDetailRoutePath,
4343
getRegistrySkillsRoutePath,
44-
getRootComposeRoutePath,
4544
getSkillDetailRoutePath,
4645
getSkillsRoutePath,
4746
} from "@/lib/route-paths";
47+
import { useOpenNewThreadPane } from "@/hooks/useOpenNewThreadPane";
4848
import {
4949
prefetchSkillDetail,
5050
useDeleteSkill,
@@ -136,6 +136,7 @@ export function SkillsLibrary() {
136136
const providerRoster = useProviderRoster();
137137
const queryClient = useQueryClient();
138138
const navigate = useNavigate();
139+
const openNewThreadPane = useOpenNewThreadPane();
139140
const location = useLocation();
140141
const { skillId: routeSkillId, registrySkillId: routeRegistrySkillId } =
141142
useParams<{
@@ -402,9 +403,8 @@ export function SkillsLibrary() {
402403
);
403404
const editSkillViaThread = useCallback(
404405
(skill: SkillSummary) => {
405-
navigate(getRootComposeRoutePath(), {
406+
openNewThreadPane({
406407
state: {
407-
focusPrompt: true,
408408
initialPrompt: buildSkillEditThreadPrompt({
409409
id: skill.id,
410410
name: skill.name,
@@ -414,7 +414,7 @@ export function SkillsLibrary() {
414414
},
415415
});
416416
},
417-
[navigate],
417+
[openNewThreadPane],
418418
);
419419
const openRegistrySkill = useCallback(
420420
(skill: RegistrySkill) => {
@@ -441,29 +441,27 @@ export function SkillsLibrary() {
441441
}, [navigate]);
442442
const handleCreateSkill = useCallback(
443443
(prompt?: string) => {
444-
navigate(getRootComposeRoutePath(), {
444+
openNewThreadPane({
445445
state: {
446-
focusPrompt: true,
447446
initialPrompt: prompt ?? CREATE_SKILL_PROMPT,
448447
replaceInitialPrompt: true,
449448
createDraftKind: "skill",
450449
},
451450
});
452451
},
453-
[navigate],
452+
[openNewThreadPane],
454453
);
455454
const forkRegistrySkill = useCallback(
456455
(skill: RegistrySkill) => {
457-
navigate(getRootComposeRoutePath(), {
456+
openNewThreadPane({
458457
state: {
459-
focusPrompt: true,
460458
initialPrompt: buildRegistrySkillReferencePrompt(skill),
461459
replaceInitialPrompt: true,
462460
createDraftKind: "skill",
463461
},
464462
});
465463
},
466-
[navigate],
464+
[openNewThreadPane],
467465
);
468466
const registryDetail = registryDetailQuery.data ?? null;
469467
const selectedLocalRegistrySkill = selectedRegistrySkill
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { useCallback } from "react";
2-
import { useRouteNavigate } from "@/components/ui/app-route-anchor";
3-
import { getRootComposeRoutePath } from "@/lib/route-paths";
4-
import { useSetRootComposeProjectId } from "@/lib/root-compose-selection";
2+
import { useOpenNewThreadPane } from "@/hooks/useOpenNewThreadPane";
53

64
interface UseCreateThreadInWorktreeArgs {
75
projectId: string;
@@ -12,12 +10,11 @@ export function useCreateThreadInWorktree({
1210
projectId,
1311
environmentId,
1412
}: UseCreateThreadInWorktreeArgs): () => void {
15-
const navigate = useRouteNavigate();
16-
const setRootComposeProjectId = useSetRootComposeProjectId();
13+
const openNewThreadPane = useOpenNewThreadPane();
1714
return useCallback(() => {
18-
setRootComposeProjectId(projectId);
19-
navigate(getRootComposeRoutePath(), {
15+
openNewThreadPane({
16+
projectId,
2017
state: { reuseEnvironmentId: environmentId },
2118
});
22-
}, [environmentId, navigate, projectId, setRootComposeProjectId]);
19+
}, [environmentId, openNewThreadPane, projectId]);
2320
}

‎apps/app/src/hooks/useForkThreadFromMessage.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ import {
77
isThreadForkable,
88
type ForkThreadCreateSeed,
99
} from "@bb/client-core";
10-
import { getRootComposeRoutePath } from "@/lib/route-paths";
1110
import { getThreadDisplayTitle } from "@/lib/thread-title";
12-
import { useSetRootComposeProjectId } from "@/lib/root-compose-selection";
11+
import { useOpenNewThreadPane } from "@/hooks/useOpenNewThreadPane";
1312
import { threadDefaultExecutionOptionsQueryKey } from "@/hooks/queries/query-keys";
1413
import { findCachedProviderInfo } from "@/hooks/queries/system-queries";
15-
import { useRouteNavigate } from "@/components/ui/app-route-anchor";
1614

1715
interface UseForkThreadFromMessageArgs {
1816
sourceThread: Thread | null;
@@ -27,9 +25,8 @@ export function useForkThreadFromMessage({
2725
}: UseForkThreadFromMessageArgs): (
2826
target: ForkThreadFromMessageTarget,
2927
) => Promise<void> {
30-
const navigate = useRouteNavigate();
3128
const queryClient = useQueryClient();
32-
const setRootComposeProjectId = useSetRootComposeProjectId();
29+
const openNewThreadPane = useOpenNewThreadPane();
3330
const forkInFlightRef = useRef(false);
3431
const sourceThreadRef = useRef(sourceThread);
3532
useLayoutEffect(() => {
@@ -77,10 +74,9 @@ export function useForkThreadFromMessage({
7774
sourceThreadId: source.id,
7875
sourceThreadTitle: getThreadDisplayTitle(source),
7976
};
80-
setRootComposeProjectId(source.projectId);
81-
navigate(getRootComposeRoutePath(), {
77+
openNewThreadPane({
78+
projectId: source.projectId,
8279
state: {
83-
focusPrompt: true,
8480
reuseEnvironmentId: source.environmentId,
8581
[FORK_THREAD_CREATE_SEED_LOCATION_STATE_KEY]: seed,
8682
},
@@ -89,6 +85,6 @@ export function useForkThreadFromMessage({
8985
forkInFlightRef.current = false;
9086
}
9187
},
92-
[navigate, queryClient, setRootComposeProjectId],
88+
[openNewThreadPane, queryClient],
9389
);
9490
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { readdirSync, readFileSync, statSync } from "node:fs";
2+
import { fileURLToPath } from "node:url";
3+
import { dirname, join, relative } from "node:path";
4+
import { describe, expect, it } from "vitest";
5+
6+
const srcRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
7+
8+
const NEW_THREAD_PANE_HOOK = "hooks/useOpenNewThreadPane.ts";
9+
10+
const SPLIT_ROUTING_FILES = [
11+
"components/sidebar/usePaneContentSplitDrag.ts",
12+
"views/thread-detail/splitThreadNavigation.ts",
13+
];
14+
15+
const NON_CREATING_NAVIGATION_FILES = [
16+
"components/layout/AppLayout.tsx",
17+
"components/project/ProjectActionsProvider.tsx",
18+
"components/thread/ThreadActionsProvider.tsx",
19+
"components/tools/PluginCapabilities.tsx",
20+
"hooks/cache-owners/resource-route-owner.ts",
21+
"hooks/useAppSettingsRouteMemory.ts",
22+
"views/RootComposeView.tsx",
23+
];
24+
25+
function listSourceFiles(directory: string): string[] {
26+
return readdirSync(directory).flatMap((entry) => {
27+
const entryPath = join(directory, entry);
28+
if (statSync(entryPath).isDirectory()) {
29+
return listSourceFiles(entryPath);
30+
}
31+
if (!/\.tsx?$/.test(entry) || /\.(test|stories)\.tsx?$/.test(entry)) {
32+
return [];
33+
}
34+
return [entryPath];
35+
});
36+
}
37+
38+
describe("new thread entry points", () => {
39+
it("routes every thread creation through the pane-opening hook", () => {
40+
const offenders = listSourceFiles(srcRoot)
41+
.filter((filePath) =>
42+
readFileSync(filePath, "utf8").includes("getRootComposeRoutePath"),
43+
)
44+
.map((filePath) => relative(srcRoot, filePath))
45+
.filter(
46+
(filePath) =>
47+
filePath !== NEW_THREAD_PANE_HOOK &&
48+
filePath !== "lib/route-paths.ts" &&
49+
!SPLIT_ROUTING_FILES.includes(filePath) &&
50+
!NON_CREATING_NAVIGATION_FILES.includes(filePath),
51+
);
52+
53+
expect(offenders).toEqual([]);
54+
});
55+
56+
it("opens the composer beside the focused pane instead of replacing it", () => {
57+
const source = readFileSync(join(srcRoot, NEW_THREAD_PANE_HOOK), "utf8");
58+
59+
expect(source).toContain("openPaneContentInSplit");
60+
expect(source).toContain('content: NEW_THREAD_PANE_CONTENT');
61+
expect(source).toContain("enabled: !isCompactViewport");
62+
});
63+
});

0 commit comments

Comments
 (0)