From df83c1d72c81a61f7e6650069afbefd302314322 Mon Sep 17 00:00:00 2001
From: Diao Shengjia <104132148+GoDiao@users.noreply.github.com>
Date: Sun, 15 Nov 2026 11:48:48 +0800
Subject: [PATCH 1/5] feat(side-chat): hide inherited messages and start a side
chat from selected text
A side chat's page now shows only its own messages; the model still reads the whole fork. Selecting text in the main conversation offers "Start a side chat | Reply"; the first opens a new side chat with the selection quoted in its composer.
---
CHANGELOG.md | 2 +-
desktop/src/components/README.md | 2 +-
.../src/components/chat/MessageList.test.tsx | 81 ++++++++++++++++++-
desktop/src/components/chat/MessageList.tsx | 47 ++++++++---
.../components/chat/SessionConversation.tsx | 4 +-
.../shared/SelectionPopover.test.tsx | 25 +++++-
.../components/shared/SelectionPopover.tsx | 25 ++++--
.../workspace/WorkspacePanel.test.tsx | 22 ++++-
.../components/workspace/WorkspacePanel.tsx | 18 +----
.../workspace/WorkspaceQuotePopover.tsx | 11 ++-
desktop/src/i18n/locales/en.ts | 2 +
desktop/src/i18n/locales/zh.ts | 2 +
desktop/src/lib/sideChats.test.ts | 12 +++
desktop/src/lib/sideChats.ts | 21 +++++
desktop/src/pages/ActiveSession.test.tsx | 6 +-
desktop/src/pages/ActiveSession.tsx | 1 +
.../src/stores/workspacePanelStore.test.ts | 2 +-
desktop/src/stores/workspacePanelStore.ts | 3 +-
docs/features/side-chat/tech-design.md | 37 ++++++++-
src/server/__tests__/session-links.test.ts | 56 +++++++++++++
src/server/services/sessionService.ts | 6 +-
src/server/transcript/entries.ts | 17 ++++
22 files changed, 351 insertions(+), 51 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 24e5a188..31917f48 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,7 +9,7 @@ All notable changes to DreamCoder will be documented in this file.
- **Sessions can start other sessions and message each other.** The agent can start a new session with `StartSession`, either fresh with a brief or as a fork of its own conversation, optionally in a new git worktree; you approve every new session, whatever the permission mode. Any session can message any other with `SendMessage`, across projects: a message wakes the receiver, and a progress report from a child to its parent waits for the parent's next turn instead of interrupting it (a parent that is already working sees it right away). Reports waiting for the parent are listed above its message box. The server stamps who sent each message, so a session cannot pass itself off as you or as another session. `ListSessions` lists sessions, and `RenameSession` lets the agent rename its own session (#239).
- **Sessions are nested in the sidebar.** Sessions the agent started, and conversations you forked, appear under the session they came from, with an icon for each kind and a count that collapses or expands them. Messages from another session appear in the conversation as a one-line row with the sender, which expands to the full text (#239).
- **Project board.** Each project gets a persistent board of tasks and sub-tasks that you and your sessions share; every worktree of the project uses the same board. Open it from the project in the sidebar. A task records its owner, reviewer and creator, acceptance criteria, priority, dependencies, progress, and the owner's and reviewer's reports. Sessions read and update the board with four tools (`KanbanList`, `KanbanGet`, `KanbanCreate`, `KanbanUpdate`): they split work into sub-tasks, record progress, block a task with a question, submit their work and review it. The board notifies the sessions involved when they are assigned, when work is submitted, blocked, sent back, reset or cancelled, and when you comment. `StartSession` can start a session as a task's owner or reviewer. The board page has a board view and a hierarchy view, opens a task in the side panel, and lists what waits on you under "Needs me": blocked tasks, deliveries to accept and tasks whose owner session is gone. You approve every time a session creates the board, starts a session on a task, cancels a task, changes acceptance criteria it did not set, or makes itself a reviewer; only a task's creator or you choose its reviewer (#242).
-- **Side chats.** Start a side chat from the side panel's new-tab page to ask about something without interrupting the session: it continues from the session's latest message, in the same working folder, with the same tools, and opens as a tab in the session's side panel. A session can have several. Pages, files and browser tabs a side chat opens appear in the same panel. The tab is named `btw: ` plus your first message; right-click it to rename it, or to detach it into a regular forked session in the sidebar. Closing the tab deletes the side chat, and deleting a session deletes its side chats. Side chats stay out of the sidebar, search and board pickers; `ListSessions` shows a session its own side chats so it can message them. Cmd+. stops the conversation that has the focus.
+- **Side chats.** Start a side chat from the side panel's new-tab page, or select text in the conversation and choose **Start a side chat** to quote it in a new one, to ask about something without interrupting the session: it continues from the session's latest message, in the same working folder, with the same tools, and opens as a tab in the session's side panel. It shows only its own messages; the model still has the whole conversation. A session can have several. Pages, files and browser tabs a side chat opens appear in the same panel. The tab is named `btw: ` plus your first message; right-click it to rename it, or to detach it into a regular forked session in the sidebar. Closing the tab deletes the side chat, and deleting a session deletes its side chats. Side chats stay out of the sidebar, search and board pickers; `ListSessions` shows a session its own side chats so it can message them. Cmd+. stops the conversation that has the focus.
### Changed
diff --git a/desktop/src/components/README.md b/desktop/src/components/README.md
index 5b332252..df1bbe82 100644
--- a/desktop/src/components/README.md
+++ b/desktop/src/components/README.md
@@ -112,7 +112,7 @@ picker through `ui/input`.
| `settings/SettingsDisclosureRow`, `chat/LocalSlashCommandPanel` | Collapsible and Tabs with shared buttons; existing content and loading behavior |
| `chat/MessageActionBar`, `chat/ImageGalleryModal`, `chat/ToolResultBlock` | Shared buttons and CopyButton; existing copy, fork, navigation and expand actions |
| `tasks/TaskRow` | Action Menu + Confirm Dialog; keyboard navigation, focus return, pending requests and retryable errors |
-| `shared/SelectionPopover` | Shared Popover + Button for chat replies and plain-code, Markdown and Pierre selection quotes; portals outside transformed message containers and preserves captured text and line coordinates |
+| `shared/SelectionPopover` | Shared Popover with a row of action buttons for chat selections (Start a side chat, Reply) and plain-code, Markdown and Pierre selection quotes; portals outside transformed message containers and preserves captured text and line coordinates |
| `workspace/PreviewLimitBar` | Sticky bar with the shown/total line count and a show-all toggle, shared by the code and diff previews |
| `workspace/WorkspaceQuotePopover` | SelectionPopover with the workspace "add to chat" action, shared by the code, Markdown and Pierre diff surfaces |
| `CommandPalette/CommandPalette`, `layout/ShortcutsDialog` | Command and Kbd respectively, with existing navigation and shortcut data |
diff --git a/desktop/src/components/chat/MessageList.test.tsx b/desktop/src/components/chat/MessageList.test.tsx
index 63cab834..9acebdb1 100644
--- a/desktop/src/components/chat/MessageList.test.tsx
+++ b/desktop/src/components/chat/MessageList.test.tsx
@@ -5,6 +5,7 @@ import { relativizeWorkspacePath } from './CurrentTurnChangeCard'
import { sessionsApi } from '../../api/sessions'
import { useChatStore } from '../../stores/chatStore'
import { useWorkspaceChatContextStore } from '../../stores/workspaceChatContextStore'
+import { useWorkspacePanelStore } from '../../stores/workspacePanelStore'
import { useSettingsStore } from '../../stores/settingsStore'
import { useSessionStore } from '../../stores/sessionStore'
import { useTabStore } from '../../stores/tabStore'
@@ -1635,7 +1636,7 @@ describe('MessageList nested tool calls', () => {
await selectMessageText(userText, 'workspace selection behavior')
const floatingAddButton = screen.getByRole('button', { name: 'Reply' })
- expect(screen.getByRole('dialog', { name: 'Reply' }).parentElement?.parentElement).toBe(document.body)
+ expect(screen.getByRole('dialog', { name: 'Selected text' }).parentElement?.parentElement).toBe(document.body)
expect(userText.closest('[data-message-shell]')?.contains(floatingAddButton)).toBe(false)
fireEvent.click(floatingAddButton)
@@ -1685,6 +1686,84 @@ describe('MessageList nested tool calls', () => {
])
})
+ describe('starting a side chat from a selection', () => {
+ function showAssistantReply() {
+ useChatStore.setState({
+ sessions: {
+ [ACTIVE_TAB]: makeSessionState({
+ messages: [{ id: 'assistant-1', type: 'assistant_text', content: 'Ask about this part later.', timestamp: 1 }],
+ }),
+ },
+ })
+ }
+
+ beforeEach(() => {
+ useWorkspacePanelStore.setState(useWorkspacePanelStore.getInitialState(), true)
+ localStorage.clear()
+ })
+
+ it('offers it before Reply in the main conversation', async () => {
+ showAssistantReply()
+ render()
+
+ await selectMessageText(screen.getByText(/Ask about this part/), 'this part')
+
+ const actions = within(screen.getByRole('dialog', { name: 'Selected text' })).getAllByRole('button')
+ expect(actions.map((button) => button.textContent)).toEqual(['Start a side chat', 'Reply'])
+ })
+
+ it('offers only Reply inside a side chat', async () => {
+ showAssistantReply()
+ render()
+
+ await selectMessageText(screen.getByText(/Ask about this part/), 'this part')
+
+ expect(within(screen.getByRole('dialog', { name: 'Selected text' })).getAllByRole('button').map((button) => button.textContent)).toEqual(['Reply'])
+ })
+
+ it('opens a new side chat with the selection quoted in its composer', async () => {
+ showAssistantReply()
+ const branch = vi.spyOn(sessionsApi, 'branch').mockResolvedValue({ sessionId: 'side-1', title: 'btw', workDir: '/repo', sourceSessionId: ACTIVE_TAB })
+ render()
+
+ await selectMessageText(screen.getByText(/Ask about this part/), 'this part')
+ fireEvent.click(screen.getByRole('button', { name: 'Start a side chat' }))
+
+ await waitFor(() => expect(screen.queryByRole('dialog', { name: 'Selected text' })).toBeNull())
+ expect(branch).toHaveBeenCalledWith(ACTIVE_TAB, { kind: 'side' })
+ expect(useWorkspacePanelStore.getState().panelByTab[ACTIVE_TAB]?.tabs).toMatchObject([{ kind: 'sideChat', sessionId: 'side-1' }])
+ expect(useWorkspaceChatContextStore.getState().referencesBySession).toEqual({
+ 'side-1': [expect.objectContaining({ kind: 'chat-selection', path: 'chat://assistant/assistant-1', messageId: 'assistant-1', quote: 'this part' })],
+ })
+ expect(window.getSelection()?.toString()).toBe('')
+ })
+
+ it('blocks a second click while the side chat is being created', async () => {
+ showAssistantReply()
+ const branch = vi.spyOn(sessionsApi, 'branch').mockReturnValue(new Promise(() => {}))
+ render()
+
+ await selectMessageText(screen.getByText(/Ask about this part/), 'this part')
+ fireEvent.click(screen.getByRole('button', { name: 'Start a side chat' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Start a side chat' }))
+
+ expect(screen.getByRole('button', { name: 'Start a side chat' })).toHaveProperty('disabled', true)
+ expect(branch).toHaveBeenCalledOnce()
+ })
+
+ it('says why a side chat could not be started', async () => {
+ showAssistantReply()
+ vi.spyOn(sessionsApi, 'branch').mockRejectedValue(new Error('busy'))
+ render()
+
+ await selectMessageText(screen.getByText(/Ask about this part/), 'this part')
+ fireEvent.click(screen.getByRole('button', { name: 'Start a side chat' }))
+
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('Could not start a side chat: busy'))
+ expect(useWorkspaceChatContextStore.getState().referencesBySession).toEqual({})
+ })
+ })
+
it('closes the selected-message action but keeps the selection when pressing outside the popover', async () => {
useChatStore.setState({
sessions: {
diff --git a/desktop/src/components/chat/MessageList.tsx b/desktop/src/components/chat/MessageList.tsx
index b6ae08b8..c1ee6ceb 100644
--- a/desktop/src/components/chat/MessageList.tsx
+++ b/desktop/src/components/chat/MessageList.tsx
@@ -32,6 +32,7 @@ import { ConfirmDialog } from '../shared/ConfirmDialog'
import { getSelectionAnchor, useQuoteSelection } from '../../lib/selectionPopover'
import { ASK_USER_QUESTION_TOOL, CHOOSE_DESIGN_TEMPLATE_TOOL, isInlineQuestionTool } from '../../lib/inlineQuestionTools'
import { SelectionPopover } from '../shared/SelectionPopover'
+import { useStartSideChat } from '../../lib/sideChats'
import {
getHeightsForSession,
getMetricsForSession,
@@ -358,42 +359,60 @@ function SelectableChatMessage({
messageId,
role,
content,
+ canStartSideChat,
children,
}: {
sessionId: string
messageId: string
role: ChatMessageRole
content: string
+ canStartSideChat: boolean
children: ReactNode
}) {
const rootRef = useRef(null)
const addReference = useWorkspaceChatContextStore((state) => state.addReference)
+ const sideChat = useStartSideChat(sessionId)
const quote = useQuoteSelection((event) => getChatSelectionFromContainer(rootRef.current, event), `${messageId}:${content}`)
const t = useTranslation()
const sourceName = role === 'assistant'
? t('chat.assistantMessageReference')
: t('chat.userMessageReference')
+ const selectionReference = () => quote.selection && {
+ kind: 'chat-selection' as const,
+ path: `chat://${role}/${messageId}`,
+ name: sourceName,
+ quote: quote.selection.text,
+ sourceRole: role,
+ messageId,
+ }
+
const addCurrentSelectionToChat = () => {
- if (!quote.selection) return
- addReference(sessionId, {
- kind: 'chat-selection',
- path: `chat://${role}/${messageId}`,
- name: sourceName,
- quote: quote.selection.text,
- sourceRole: role,
- messageId,
- })
+ const reference = selectionReference()
+ if (!reference) return
+ addReference(sessionId, reference)
quote.dismiss()
}
+ const startSideChatFromSelection = async () => {
+ const reference = selectionReference()
+ if (!reference) return
+ await sideChat.start(reference)
+ quote.dismiss()
+ }
+
+ const replyAction = { label: t('chat.replyToSelection'), onSelect: addCurrentSelectionToChat }
+ const actions = canStartSideChat
+ ? [{ label: t('chat.startSideChat'), loading: sideChat.starting, onSelect: () => void startSideChatFromSelection() }, replyAction]
+ : [replyAction]
+
return (