Skip to content

Commit fa7bb66

Browse files
authored
feat(web): General Chats can be a section of Threads instead of their own page (#1031)
* feat(web): General Chats can be a section of Threads instead of their own page Issue #1016 asked for General Chats at the bottom of the Threads list so switching between project work and chats takes no extra step. Some people like the separate page, so this is a per-device choice: Settings > Threads > Sidebar > General chats, "Own page" (default, unchanged) or "Section in Threads". In section mode the General Chats rail button goes away and its counts move onto Threads. The chats sit in a fold-out section under Wrapped with the same header line (now one shared InboxShelfHeader) and a New chat button; folded, it keeps the open chat's row and says what the hidden chats need or are doing. /chats, and so the command palette, desktop menu and place links, opens Threads with the section open, showing a floating list or the phone sheet. The inbox column leaves the section its room. The chat rows are shared with the page list (GeneralChatRows), and the palette gains "New general chat". * fix(web): General chats section follows the computer filter and opens without a detour Review fixes on the General chats section: - Opening it from the command palette or the desktop menu no longer stops at /chats: a request goes to one GeneralChatsRevealer in the shell, which unfolds the section, shows the list or the phone sheet, and moves to Threads only when Threads isn't already on screen. Back no longer repeats the thread you were on. - A launch straight onto /chats in a narrow window keeps the floating list showing through home's own redirect to the last thread. - Switching back to the chats' own page no longer leaves the Threads button pointing at a general chat: it remembers project work separately. - With the section open, previous/next walk the whole list top to bottom, from the last project thread into the chats and back. - With the list narrowed to one computer, the section lists only that computer's chats and New chat starts there. * test(web): client settings fixtures carry generalChatsPlacement * perf(web): the General chats section loads only where it is used The section and its chat rows are now a chunk of their own, fetched only on a device that lists General Chats in Threads, and the revealer mounts only there. The section takes the sheet's close action as a prop rather than importing the sidebar's context, which would have split that context out of the startup bundle. Reveal requests now wait as a pending count, so one made before the revealer mounts is still carried out. Startup closure, local build: 924,408 B before, 912,235 B after (main reads 910,464 B). * test(web): the phone's destination row fits with General Chats and Terminals both in it
1 parent fd3445c commit fa7bb66

29 files changed

Lines changed: 1322 additions & 255 deletions

‎apps/desktop/src/settings/DesktopClientSettings.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const clientSettings: ClientSettings = {
4545
providerModelPreferences: {},
4646
suppressCrossProviderSwitchWarning: false,
4747
sidebarGrouping: "none",
48+
generalChatsPlacement: "page",
4849
inboxSort: "recent",
4950
inboxCustomOrder: [],
5051
inboxGroupOrder: [],

‎apps/server/src/guide/topics.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const GUIDE_TOPICS: ReadonlyArray<GuideTopic> = [
4242
"wrap",
4343
"archive",
4444
"restart",
45+
"general chats",
4546
],
4647
body: `A thread is one conversation with an agent in a project. Threads are listed in the sidebar; one that needs you, finished or failed says so there. In a narrow window the sidebar floats over the thread instead of sitting beside it: the sidebar button at the top left, or Cmd+B (Ctrl+B on Windows and Linux), opens it, and picking a thread or clicking the thread puts it away. A thread you scrolled up in opens where you left it when you come back, until Threadlines reloads; one that finished, failed or needs you since then opens at the end.
4748
@@ -63,6 +64,8 @@ When Claude or Codex asks multiple-choice questions, a card takes the place of t
6364
6465
When a thread is done it wraps up and moves to the Wrapped shelf at the bottom of the sidebar; {place:threads.whenDone} says when that happens on its own. An agent coming back later (a check-back) doesn't keep a thread out of Wrapped: the thread returns to the list when the agent does. Old threads can be archived for you: {place:archived.cleanup}.
6566
67+
General Chats are chats with an agent that aren't tied to a project. By default they have their own page in the left bar, with a New chat button over the list. With {place:threads.generalChats} set to Section in Threads, that button leaves the left bar and the chats sit in a General chats section at the bottom of the thread list, under Wrapped: its header opens and closes it and has its own New chat button, and the Threads button counts what the chats need and are doing. Old General Chats links then open Threads with the section open. Each device keeps its own choice.
68+
6669
When Threadlines quits, updates or crashes while an agent works on something the user asked for, the agent picks it back up when Threadlines starts again: the chat gets a message marked "Sent after a restart" telling the agent to check before repeating anything. A turn waiting on an approval or a question, or one another thread, a scheduled task or an outside agent started, stops with a note instead, as does a turn restarts cut off three times in five minutes. {place:threads.continueAfterRestart} turns this off.`,
6770
},
6871
{

‎apps/web/src/components/AppSidebarLayout.tsx‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { useAppHistory } from "../appHistory";
1616
import { useCommandPaletteStore } from "../commandPaletteStore";
1717
import { isKnownEnvironment } from "../environments/runtime";
1818
import { useHandleNewThread } from "../hooks/useHandleNewThread";
19+
import { getClientSettings } from "../hooks/useSettings";
1920
import { resolveShortcutCommand } from "../keybindings";
2021
import { startNewThreadFromContext } from "../lib/chatThreadActions";
2122
import { isTerminalFocused } from "../lib/terminalFocus";
@@ -26,6 +27,12 @@ import { selectThreadTerminalState, useTerminalStateStore } from "../terminalSta
2627
import { buildThreadRouteParams } from "../threadRoutes";
2728
import { selectSidebarListShown, useUiStateStore } from "../uiStateStore";
2829
import ThreadSidebar from "./Sidebar";
30+
import {
31+
consumeSidebarListReveal,
32+
requestGeneralChatsReveal,
33+
useGeneralChatsInThreads,
34+
} from "./chats/generalChatsPlacement";
35+
import { GeneralChatsRevealer } from "./chats/GeneralChatsRevealer";
2936
import { AppTitleBar } from "./sidebar/AppTitleBar";
3037
import { TitleBarSlotContext } from "./sidebar/titleBarSlot";
3138
import { destinationHasList } from "./sidebar/destinationLists";
@@ -144,7 +151,9 @@ function AppShellCommands({ hasList }: { readonly hasList: boolean }) {
144151
void navigate({ to: "/terminals" });
145152
return;
146153
case "open-general-chats":
147-
void navigate({ to: "/chats" });
154+
// Read when the item fires; the menu subscription stays put.
155+
if (getClientSettings().generalChatsPlacement === "threads") requestGeneralChatsReveal();
156+
else void navigate({ to: "/chats" });
148157
return;
149158
case "open-usage":
150159
void navigate({ to: "/usage" });
@@ -295,18 +304,22 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
295304
const listFloats = useUiStateStore((store) => store.sidebarListFloats);
296305
const setSidebarListShown = useUiStateStore((store) => store.setSidebarListShown);
297306
const selectedDestination = useSelectedDestination();
307+
const generalChatsInThreads = useGeneralChatsInThreads();
298308
const hasList = destinationHasList(selectedDestination);
299309
const isMobile = useIsMobile();
300310
const panelRef = useRef<HTMLDivElement>(null);
301311
useSidebarListFloats(panelRef, isMobile);
302-
// A floating list gets out of the way of whatever page opens next.
312+
// A floating list gets out of the way of whatever page opens next, unless
313+
// the change was asked to show it (opening the chats' section in Threads,
314+
// GeneralChatsRevealer).
303315
const pathname = useLocation({ select: (location) => location.pathname });
304316
const shownPathname = useRef(pathname);
305317
useEffect(() => {
306318
if (shownPathname.current === pathname) return;
307319
shownPathname.current = pathname;
308320
const state = useUiStateStore.getState();
309-
if (state.sidebarListFloats) state.setSidebarListShown(false);
321+
if (consumeSidebarListReveal(pathname)) state.setSidebarListShown(true);
322+
else if (state.sidebarListFloats) state.setSidebarListShown(false);
310323
}, [pathname]);
311324
usePageCrossFade(panelRef, selectedDestination);
312325
// Dialogs and other window-wide layers center over the page beside the list.
@@ -354,6 +367,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
354367
style={sidebarStyle}
355368
>
356369
<AppShellCommands hasList={hasList} />
370+
{generalChatsInThreads ? <GeneralChatsRevealer /> : null}
357371
<AppTitleBar slotRef={setTitleBarSlot} />
358372
<div className="flex min-h-0 flex-1">
359373
<NavigationRail />

‎apps/web/src/components/ChatView.browser-harness.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,6 +3482,7 @@ export function registerChatViewSuiteHooks(): void {
34823482
inboxProjectScopeKeys: [],
34833483
collapsedInboxGroups: {},
34843484
inboxWrappedOpen: false,
3485+
inboxGeneralChatsOpen: true,
34853486
sidebarListOpen: true,
34863487
});
34873488
useTerminalStateStore.persist.clearStorage();

‎apps/web/src/components/ChatView.shell.browser.tsx‎

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import * as Effect from "effect/Effect";
1515
import { page, userEvent } from "vite-plus/test/browser";
1616
import { describe, expect, it, vi } from "vite-plus/test";
1717

18+
import { DEFAULT_CLIENT_SETTINGS } from "@threadlines/contracts/settings";
19+
20+
import { CLIENT_SETTINGS_STORAGE_KEY } from "../clientPersistenceStorage";
1821
import { useComposerDraftStore } from "../composerDraftStore";
1922
import { isMacPlatform } from "../lib/utils";
2023
import { useOptimisticThreadMessagesStore } from "../optimisticThreadMessages";
@@ -1091,6 +1094,90 @@ describe("ChatView (full app): app shell", () => {
10911094
}
10921095
});
10931096

1097+
it("shows a floating list with the chats' section open when the old General Chats address leads to Threads", async () => {
1098+
localStorage.setItem(
1099+
CLIENT_SETTINGS_STORAGE_KEY,
1100+
JSON.stringify({ ...DEFAULT_CLIENT_SETTINGS, generalChatsPlacement: "threads" }),
1101+
);
1102+
useUiStateStore.setState({ inboxGeneralChatsOpen: false });
1103+
const mounted = await mountChatView({
1104+
viewport: { ...DEFAULT_VIEWPORT, name: "list-floats-chats", width: 800 },
1105+
snapshot: createSnapshotForTargetUser({
1106+
targetMessageId: "msg-user-list-floats-chats" as MessageId,
1107+
targetText: "list floats chats",
1108+
}),
1109+
});
1110+
1111+
try {
1112+
const list = await waitForElement(
1113+
() =>
1114+
document.querySelector<HTMLElement>('[data-testid="app-panel"] > [data-slot="sidebar"]'),
1115+
"Unable to find the list beside the rail.",
1116+
);
1117+
await vi.waitFor(() => expect(list.dataset.state).toBe("collapsed"));
1118+
const threadPath = mounted.router.state.location.pathname;
1119+
// From another page, as the command palette or the desktop menu would go.
1120+
await mounted.router.navigate({ to: "/fleet" });
1121+
await waitForURL(mounted.router, (pathname) => pathname === "/fleet", "Fleet should open.");
1122+
await mounted.router.navigate({ to: "/chats" });
1123+
await waitForURL(
1124+
mounted.router,
1125+
(pathname) => pathname === threadPath,
1126+
"The old General Chats address should go where the Threads button does.",
1127+
);
1128+
// Both page changes (to the old address, then on to Threads) leave it showing.
1129+
await nextFrames(5);
1130+
expect(list.dataset.state).toBe("expanded");
1131+
await expect
1132+
.element(page.getByTestId("inbox-chats-toggle"))
1133+
.toHaveAttribute("aria-expanded", "true");
1134+
// The next page change puts the floating list away as usual.
1135+
await mounted.router.navigate({ to: "/fleet" });
1136+
await vi.waitFor(() => expect(list.dataset.state).toBe("collapsed"));
1137+
} finally {
1138+
localStorage.removeItem(CLIENT_SETTINGS_STORAGE_KEY);
1139+
await mounted.cleanup();
1140+
}
1141+
});
1142+
1143+
it("keeps a floating list showing when the app opens on the old General Chats address", async () => {
1144+
localStorage.setItem(
1145+
CLIENT_SETTINGS_STORAGE_KEY,
1146+
JSON.stringify({ ...DEFAULT_CLIENT_SETTINGS, generalChatsPlacement: "threads" }),
1147+
);
1148+
useUiStateStore.setState({ inboxGeneralChatsOpen: false });
1149+
const mounted = await mountChatView({
1150+
viewport: { ...DEFAULT_VIEWPORT, name: "list-floats-chats-launch", width: 800 },
1151+
initialPath: "/chats",
1152+
snapshot: createSnapshotForTargetUser({
1153+
targetMessageId: "msg-user-list-floats-chats-launch" as MessageId,
1154+
targetText: "list floats chats launch",
1155+
}),
1156+
});
1157+
1158+
try {
1159+
// Home, then on to where the launch lands: the list stays out through both.
1160+
await waitForURL(
1161+
mounted.router,
1162+
(pathname) => pathname !== "/chats" && pathname !== "/",
1163+
"The launch should land in work.",
1164+
);
1165+
const list = await waitForElement(
1166+
() =>
1167+
document.querySelector<HTMLElement>('[data-testid="app-panel"] > [data-slot="sidebar"]'),
1168+
"Unable to find the list beside the rail.",
1169+
);
1170+
await nextFrames(5);
1171+
expect(list.dataset.state).toBe("expanded");
1172+
await expect
1173+
.element(page.getByTestId("inbox-chats-toggle"))
1174+
.toHaveAttribute("aria-expanded", "true");
1175+
} finally {
1176+
localStorage.removeItem(CLIENT_SETTINGS_STORAGE_KEY);
1177+
await mounted.cleanup();
1178+
}
1179+
});
1180+
10941181
it("folds the app's name away, then gives the thread's header its own row, as the title row runs out of room", async () => {
10951182
const root = document.documentElement;
10961183
root.classList.add("electron", "wco");
@@ -1769,7 +1856,14 @@ describe("ChatView (full app): app shell", () => {
17691856
// A finger can't hover for the tooltip: each icon says its name.
17701857
await expect
17711858
.element(page.getByTestId("sidebar-destination-row"))
1772-
.toMatchTextContent(/Threads.*Chats.*Settings/);
1859+
.toMatchTextContent(/Threads.*Chats.*Shells.*Settings/);
1860+
// Every destination fits the phone's width, Settings last.
1861+
const row = document.querySelector<HTMLElement>('[data-testid="sidebar-destination-row"]')!;
1862+
expect(row.scrollWidth).toBeLessThanOrEqual(row.clientWidth);
1863+
const settingsButton = row.querySelector<HTMLElement>('[data-testid="rail-settings"]')!;
1864+
expect(settingsButton.getBoundingClientRect().right).toBeLessThanOrEqual(
1865+
row.getBoundingClientRect().right,
1866+
);
17731867
// The page shows a thumb's width beside the sheet: a strip to tap it shut.
17741868
const sheet = document.querySelector<HTMLElement>(
17751869
'[data-slot="sidebar"][data-mobile="true"]',
@@ -1795,6 +1889,76 @@ describe("ChatView (full app): app shell", () => {
17951889
}
17961890
});
17971891

1892+
it("on a phone with the chats in Threads, opens the sheet on them from the old page's address", async () => {
1893+
const chatId = "thread-phone-chat-section" as ThreadId;
1894+
const base = addThreadToSnapshot(
1895+
createSnapshotForTargetUser({
1896+
targetMessageId: "msg-user-phone-chat-section" as MessageId,
1897+
targetText: "phone chat section",
1898+
}),
1899+
chatId,
1900+
);
1901+
localStorage.setItem(
1902+
CLIENT_SETTINGS_STORAGE_KEY,
1903+
JSON.stringify({ ...DEFAULT_CLIENT_SETTINGS, generalChatsPlacement: "threads" }),
1904+
);
1905+
useUiStateStore.setState({ inboxGeneralChatsOpen: false });
1906+
const mounted = await mountChatView({
1907+
viewport: PHONE_VIEWPORT,
1908+
snapshot: {
1909+
...base,
1910+
projects: [
1911+
...base.projects,
1912+
{
1913+
id: GENERAL_CHATS_PROJECT_ID,
1914+
kind: "general-chat" as const,
1915+
title: "General Chats",
1916+
workspaceRoot: "/repo/general-chats",
1917+
defaultModelSelection: null,
1918+
scripts: [],
1919+
createdAt: NOW_ISO,
1920+
updatedAt: NOW_ISO,
1921+
deletedAt: null,
1922+
},
1923+
],
1924+
threads: base.threads.map((thread) =>
1925+
thread.id === chatId
1926+
? { ...thread, projectId: GENERAL_CHATS_PROJECT_ID, title: "Pocket question" }
1927+
: thread,
1928+
),
1929+
},
1930+
});
1931+
1932+
try {
1933+
await mounted.router.navigate({ to: "/chats" });
1934+
await waitForURL(
1935+
mounted.router,
1936+
(pathname) => pathname !== "/chats",
1937+
"The old General Chats address should open Threads.",
1938+
);
1939+
// The sheet opens on the thread list, with no Chats icon and the section open.
1940+
await expect
1941+
.element(page.getByTestId("sidebar-destination-row"))
1942+
.toMatchTextContent(/Threads.*Settings/);
1943+
expect(document.querySelector('[data-testid="rail-chats"]')).toBeNull();
1944+
await expect
1945+
.element(page.getByTestId("inbox-chats-toggle"))
1946+
.toHaveAttribute("aria-expanded", "true");
1947+
await expect.element(page.getByTestId(`thread-row-${THREAD_ID}`)).toBeVisible();
1948+
1949+
await page.getByTestId("chats-list-row").filter({ hasText: "Pocket question" }).click();
1950+
await waitForURL(
1951+
mounted.router,
1952+
(pathname) => pathname.endsWith(`/${chatId}`),
1953+
"A chat in the sheet should open that chat.",
1954+
);
1955+
await expect.element(page.getByTestId("sidebar-destination-row")).not.toBeInTheDocument();
1956+
} finally {
1957+
localStorage.removeItem(CLIENT_SETTINGS_STORAGE_KEY);
1958+
await mounted.cleanup();
1959+
}
1960+
});
1961+
17981962
it("navigates phone settings through the full-page section index", async () => {
17991963
const mounted = await mountChatView({
18001964
viewport: PHONE_VIEWPORT,

0 commit comments

Comments
 (0)