Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion desktop/src/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
52 changes: 52 additions & 0 deletions desktop/src/components/chat/ChatInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,58 @@ describe('ChatInput file mentions', () => {
expect(mocks.wsSend).not.toHaveBeenCalledWith(sessionId, expect.anything())
})

it('takes the focus in a side chat when asked to', () => {
const sideId = 'side-focus'
useChatStore.setState((state) => ({ sessions: { ...state.sessions, [sideId]: state.sessions[sessionId]! } }))
render(
<>
<button type="button">elsewhere</button>
<ChatInput sessionId={sideId} compact primary={false} autoFocus />
</>,
)

expect(screen.getByRole('textbox')).toHaveFocus()
})

it.each([
['the main composer', true, true],
['a side chat composer', false, false],
] as const)('shows the tools menu and the controls row in %s: %s', (_name, primary, shown) => {
render(<ChatInput sessionId={sessionId} compact primary={primary} />)

expect(screen.queryByRole('button', { name: 'Open composer tools' }) !== null).toBe(shown)
expect(screen.queryByTestId('chat-input-controls') !== null).toBe(shown)
})

it.each([
['the main composer', true, true],
['a side chat composer', false, false],
] as const)('takes dropped and pasted files in %s: %s', async (_name, primary, accepted) => {
Object.defineProperty(window, 'dreamcoderShell', { configurable: true, value: {} })
const droppedFile = new File(['log'], 'dropped.log', { type: 'text/plain' })
Object.defineProperty(droppedFile, 'path', { configurable: true, value: '/tmp/dropped.log' })
const dataTransfer = { types: ['Files'], files: [droppedFile], dropEffect: '' }
const image = new File(['png'], 'shot.png', { type: 'image/png' })
const imageItem = { kind: 'file', type: 'image/png', getAsFile: () => image }
render(<ChatInput sessionId={sessionId} compact primary={primary} />)

const panel = screen.getByTestId('chat-input-panel')
fireEvent.dragOver(panel, { dataTransfer })
expect(screen.queryByTestId('chat-input-drop-overlay') !== null).toBe(accepted)
fireEvent.drop(panel, { dataTransfer })
const imagePasteKept = fireEvent.paste(screen.getByRole('textbox'), { clipboardData: { items: [imageItem] } })
const textPasteKept = fireEvent.paste(screen.getByRole('textbox'), { clipboardData: { items: [{ kind: 'string', type: 'text/plain', getAsFile: () => null }] } })

expect(imagePasteKept).toBe(!accepted)
expect(textPasteKept).toBe(true)
if (accepted) expect(await screen.findByText('dropped.log')).toBeInTheDocument()
else {
await act(async () => { await Promise.resolve() })
expect(screen.queryByText('dropped.log')).not.toBeInTheDocument()
expect(screen.queryByText(/pasted-image/)).not.toBeInTheDocument()
}
})

it('leaves typing elsewhere on the page alone in a side chat', () => {
const sideId = 'side-typing'
useChatStore.setState((state) => ({ sessions: { ...state.sessions, [sideId]: state.sessions[sessionId]! } }))
Expand Down
32 changes: 15 additions & 17 deletions desktop/src/components/chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { FileSearchMenu, type FileSearchMenuHandle } from './FileSearchMenu'
import { LocalSlashCommandPanel, type LocalSlashCommandName } from './LocalSlashCommandPanel'
import { ContextUsageIndicator } from './ContextUsageIndicator'
import { ProviderGateCard, useProviderMissing } from './ProviderRequiredNotice'
import { ComposerBox, ComposerControls, resizeComposerTextarea } from './ComposerShell'
import { ComposerBox, ComposerControls } from './ComposerShell'
import { ProjectLabel } from './ProjectLabel'
import {
FALLBACK_SLASH_COMMANDS,
Expand Down Expand Up @@ -66,6 +66,7 @@ type ChatInputProps = {
variant?: 'default' | 'hero'
compact?: boolean
primary?: boolean
autoFocus?: boolean
}

const EMPTY_WORKSPACE_REFERENCES: WorkspaceChatReference[] = []
Expand Down Expand Up @@ -108,7 +109,7 @@ function insertComposerTokenAtRange(value: string, start: number, end: number, t
}
}

export function ChatInput({ sessionId, variant = 'default', compact = false, primary = true }: ChatInputProps) {
export function ChatInput({ sessionId, variant = 'default', compact = false, primary = true, autoFocus = false }: ChatInputProps) {
const t = useTranslation()
const isMobileComposer = useMobileViewport() && !isDesktopRuntime()
const [input, setInput] = useState('')
Expand Down Expand Up @@ -197,9 +198,10 @@ export function ChatInput({ sessionId, variant = 'default', compact = false, pri
const isActive = chatState !== 'idle'
const isWorkspaceMissing = activeSession?.workDirExists === false
const hasWorkspaceReferences = !isMemberSession && workspaceReferences.length > 0
const isHeroComposer = variant === 'hero' && primary && !isMemberSession && !compact
const fullComposer = primary && !isMemberSession
const isHeroComposer = variant === 'hero' && fullComposer && !compact
const resolvedWorkDir = activeSession?.workDir || gitInfo?.workDir || undefined
const showLaunchControls = primary && !isMemberSession && messageCount === 0
const showLaunchControls = fullComposer && messageCount === 0
const useCompactControls = compact || isMobileComposer
const activeLaunchWorkDir = showLaunchControls ? (launchWorkDir || resolvedWorkDir || '') : (resolvedWorkDir || '')
const pendingSlashUiAction = !isMemberSession && input.trim().startsWith('/')
Expand Down Expand Up @@ -258,8 +260,8 @@ export function ChatInput({ sessionId, variant = 'default', compact = false, pri
}, [saveComposerDraft])

useEffect(() => {
if (primary) textareaRef.current?.focus()
}, [isActive, primary])
if (primary || autoFocus) textareaRef.current?.focus()
}, [isActive, primary, autoFocus])

useEffect(() => {
if (!composerPrefill) return
Expand Down Expand Up @@ -337,10 +339,10 @@ export function ChatInput({ sessionId, variant = 'default', compact = false, pri
}, [refreshGitInfo])

useEffect(() => {
if (isMemberSession || messageCount === 0) return
if (!fullComposer || messageCount === 0) return
const timeout = setTimeout(refreshGitInfo, chatState === 'idle' ? 0 : 500)
return () => clearTimeout(timeout)
}, [sessionId, chatState, isMemberSession, messageCount, refreshGitInfo, slashCommandCount])
}, [sessionId, chatState, fullComposer, messageCount, refreshGitInfo, slashCommandCount])

useEffect(() => {
if (!isMemberSession) return
Expand All @@ -362,10 +364,6 @@ export function ChatInput({ sessionId, variant = 'default', compact = false, pri
})
}, [activeSession?.workDir, sessionId, gitInfo?.workDir, showLaunchControls])

useEffect(() => {
resizeComposerTextarea(textareaRef.current)
}, [input, providerMissing])




Expand Down Expand Up @@ -729,7 +727,7 @@ export function ChatInput({ sessionId, variant = 'default', compact = false, pri
}

const handlePaste = (event: React.ClipboardEvent) => {
if (isMemberSession) return
if (!fullComposer) return
const items = event.clipboardData?.items
if (!items) return
const files = clipboardImageFiles(items)
Expand All @@ -755,7 +753,7 @@ export function ChatInput({ sessionId, variant = 'default', compact = false, pri
}, [setComposerAttachments])

const { isDragActive, dragHandlers } = useComposerFileDrop({
disabled: isMemberSession || isWorkspaceMissing,
disabled: !fullComposer || isWorkspaceMissing,
onAttachments: appendAttachments,
onError: (error) => {
console.warn('[attachments] Failed to read dropped files', error)
Expand Down Expand Up @@ -990,7 +988,7 @@ export function ChatInput({ sessionId, variant = 'default', compact = false, pri
dragHandlers={dragHandlers}
overlays={overlays}
mobile={isMobileComposer}
plusMenu={isMemberSession ? undefined : {
plusMenu={fullComposer ? {
open: plusMenuOpen,
onToggle: () => setPlusMenuOpen((value) => !value),
onClose: () => setPlusMenuOpen(false),
Expand All @@ -999,7 +997,7 @@ export function ChatInput({ sessionId, variant = 'default', compact = false, pri
addFilesLabel,
slashCommandsLabel,
toggleLabel: t('chat.composerTools'),
}}
} : undefined}
textareaRef={textareaRef}
textareaProps={{
value: input,
Expand All @@ -1021,7 +1019,7 @@ export function ChatInput({ sessionId, variant = 'default', compact = false, pri
}}
/>

{!isMemberSession && (
{fullComposer && (
<ComposerControls
testId="chat-input-controls"
left={(
Expand Down
65 changes: 64 additions & 1 deletion desktop/src/components/chat/ComposerShell.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import { createRef, useRef, useState } from 'react'
import '@testing-library/jest-dom'
import { describe, expect, it, vi } from 'vitest'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { ComposerBox } from './ComposerShell'

function Harness({ onOuterEscape }: { onOuterEscape: () => void }) {
Expand Down Expand Up @@ -89,3 +89,66 @@ describe('ComposerBox plus menu', () => {
expect(screen.getByRole('textbox', { name: 'Message' })).toHaveFocus()
})
})

describe('ComposerBox height', () => {
afterEach(() => vi.unstubAllGlobals())

function renderBox(value: string) {
const textareaRef = createRef<HTMLTextAreaElement>()
const box = (text: string) => (
<ComposerBox
panelRef={createRef<HTMLDivElement>()}
testId="composer"
textareaRef={textareaRef}
textareaProps={{ 'aria-label': 'Message', value: text, onChange: () => {} }}
action={{ mode: 'send', disabled: true, onClick: () => {}, label: 'Send' }}
/>
)
const view = render(box(value))
return { textarea: screen.getByRole('textbox', { name: 'Message' }), rerender: (text: string) => view.rerender(box(text)) }
}

function observeResizes() {
const callbacks: ResizeObserverCallback[] = []
vi.stubGlobal('ResizeObserver', class {
constructor(callback: ResizeObserverCallback) { callbacks.push(callback) }
observe() {}
unobserve() {}
disconnect() {}
})
return (width: number) => {
for (const callback of callbacks) callback([{ contentRect: { width } } as ResizeObserverEntry], {} as ResizeObserver)
}
}

function setScrollHeight(textarea: HTMLElement, height: number) {
Object.defineProperty(textarea, 'scrollHeight', { configurable: true, value: height })
}

it('measures again when the box gets wider, and only then', () => {
const resize = observeResizes()
const { textarea } = renderBox('')
setScrollHeight(textarea, 154)
resize(40)
expect(textarea.style.height).toBe('154px')

setScrollHeight(textarea, 32)
resize(400)
expect(textarea.style.height).toBe('32px')

setScrollHeight(textarea, 60)
resize(400)
expect(textarea.style.height).toBe('32px')
})

it('grows with its text up to the maximum height', () => {
const { textarea, rerender } = renderBox('')
setScrollHeight(textarea, 54)
rerender('two\nlines')
expect(textarea.style.height).toBe('54px')

setScrollHeight(textarea, 900)
rerender('many\nlines')
expect(textarea.style.height).toBe('200px')
})
})
26 changes: 23 additions & 3 deletions desktop/src/components/chat/ComposerShell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tooltip as HintTooltip } from '../shared/Tooltip'
import { type DragEventHandler, type ReactNode, type RefObject, type TextareaHTMLAttributes } from 'react'
import { useEffect, type DragEventHandler, type ReactNode, type RefObject, type TextareaHTMLAttributes } from 'react'
import { ArrowUp, Paperclip, Plus, Square } from 'lucide-react'
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '../shared/ui/dropdown-menu'
import { Button } from '../shared/ui/button'
Expand Down Expand Up @@ -61,6 +61,7 @@ export function ComposerBox({
}: ComposerBoxProps) {
const ActionIcon = action.mode === 'stop' ? Square : ArrowUp
const actionActive = action.mode === 'stop' || !action.disabled
useComposerTextareaHeight(textareaRef, textareaProps.value)

return (
<div
Expand Down Expand Up @@ -124,12 +125,31 @@ export function ComposerControls({ left, right, testId = 'composer-controls' }:
}

/** Auto-grows a textarea from one line up to the composer's max height. */
export function resizeComposerTextarea(el: HTMLTextAreaElement | null) {
if (!el) return
function resizeComposerTextarea(el: HTMLTextAreaElement) {
el.style.height = 'auto'
el.style.height = `${Math.min(el.scrollHeight, COMPOSER_TEXTAREA_MAX_HEIGHT)}px`
}

function useComposerTextareaHeight(textareaRef: RefObject<HTMLTextAreaElement | null>, value: unknown) {
useEffect(() => {
if (textareaRef.current) resizeComposerTextarea(textareaRef.current)
}, [textareaRef, value])

useEffect(() => {
const el = textareaRef.current
if (!el || typeof ResizeObserver === 'undefined') return
let width: number | undefined
const observer = new ResizeObserver(([entry]) => {
const nextWidth = entry?.contentRect.width
if (nextWidth === undefined || nextWidth === width) return
width = nextWidth
resizeComposerTextarea(el)
})
observer.observe(el)
return () => observer.disconnect()
}, [textareaRef])
}


function ComposerPlusMenu({
open,
Expand Down
Loading
Loading