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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to DreamCoder will be documented in this file.
- **A cleaner desktop look.** All seven themes share one set of semantic colors, the conversation, sidebar and panels use one type scale (14px body text), and corners use one radius scale. The pages of the side panel (terminal, browser, files, changes) no longer draw their own frames; the terminal follows the light or dark theme, its project and branch sit in a row above the output with the clear and restart buttons, and the browser shows a loading bar under its address field.
- **The Files tab previews a file beside the tree.** Clicking a file in the tree previews it in place instead of opening a tab; the tree's right-click menu can still open it in its own tab, and recent files and typed paths on the new-tab page select the file in the Files tab. A path bar above the preview holds an editor button with a menu of editors and file managers, a preview toggle for Markdown (which opens rendered), a line-wrap toggle (on by default) and a tree toggle; in a narrow panel the tree shows until you pick a file, then hides. Each part of the path has a menu (add to chat and copy path; folders can also open in an editor, the file manager or a terminal tab started there), shows its full path on hover, and is revealed in the tree when clicked. Right-clicking a file's content adds the file or the selection to the chat, copies its path or contents, and in source view comments on the clicked line or selects all. The file tree is built on `@pierre/trees`. `.bmp` and `.ico` files now preview as images.
- **Changed files** have an open-file button and a menu on each row (add to chat, copy path, open file, open in an editor or the file manager).
- The card with a turn's changed files in the conversation starts as one line with the number of files, the lines added and removed and the undo button. Click the line to list the files, now in compact rows with the folder in a lighter color; a file's diff no longer repeats the file name above it.
- **Line comments are lighter.** A comment icon appears beside the line number under the pointer in code and diffs; clicking the number opens a small box with the line label, where Enter adds the comment, Shift+Enter starts a new line and Escape cancels. An empty box closes when you click elsewhere.
- **Skill details have an Overview and a Contents tab.** Overview shows the description and the other frontmatter fields, with the source, plugin, slash command, version, size and location beside them; Contents shows the skill's files in a tree beside a preview, where Markdown opens rendered and can switch to its source, images show as images, and binary or oversized files say they cannot be previewed instead of showing their bytes as text. The page no longer repeats the same facts in stat cards and metadata cards.
- The "open project" button in the session header is a split button: the icon opens the project in the editor you used last, the arrow lists the other editors and file managers.
Expand Down
3 changes: 2 additions & 1 deletion desktop/src/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ that only renames props or passes them through does not belong here.
| `CardButton` | A button with the card surface, hover, disabled and focus styles; sizing and borders come from the caller |
| `ViewerHeader` | The header of a full-screen page viewer: back button, title and actions, as the window's title row (drag region, title bar height on macOS) |
| `SearchField` | Input Group, Input and lucide search/clear icons |
| `FilePathLabel` | A file path inside a row: the file name, then its folder in the subtle text color, truncated together; shared by the Changes tab and the turn change card in the conversation |
| `SegmentedControl` | Single-selection Toggle Group |
| `Dropdown` | Dropdown Menu radio items with optional descriptions, shared by settings selects and the workspace view switch |
| `FormSelect` | Select with labelled triggers and empty application values encoded as nonempty Radix item values |
Expand All @@ -71,7 +72,7 @@ that only renames props or passes them through does not belong here.
| `ResponsivePopover` | Popover on desktop and bottom sheet on mobile |
| `CopyButton` | Button, Tooltip and `useCopyAndNotify`, which wraps the clipboard helper with localized success and failure toasts |
| `DirectoryPicker`, `RepositoryLaunchControls` | DreamCoder project/branch workflows using shared popovers, Command and controls |
| `PierreDiffSurface` | DreamCoder adapter around [`@pierre/diffs`](https://diffs.com), with token overrides in [`pierre.css`](shared/pierre.css) |
| `PierreDiffSurface` | DreamCoder adapter around [`@pierre/diffs`](https://diffs.com), with token overrides in [`pierre.css`](shared/pierre.css). Pierre's own file header is always off; the caller shows the file name |
| `DreamCoderIcon` | DreamCoder brand artwork; not a general-purpose icon set |
| `UpdateChecker` | Nonblocking persistent Sonner notification with Card, Button and Progress; updater state remains in the existing store |

Expand Down
148 changes: 148 additions & 0 deletions desktop/src/components/chat/CurrentTurnChangeCard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import '@testing-library/jest-dom'
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { sessionsApi, type SessionTurnCheckpoint } from '../../api/sessions'
import { useSettingsStore } from '../../stores/settingsStore'
import { CurrentTurnChangeCard } from './CurrentTurnChangeCard'

const checkpoint = (filesChanged: string[], insertions = 418, deletions = 0): SessionTurnCheckpoint => ({
target: { targetUserMessageId: 'user-1', userMessageIndex: 0, userMessageCount: 1 },
code: { available: true, filesChanged, insertions, deletions },
})

const FILES = ['/repo/dc_artifacts/talk/slides/cover.html', '/repo/README.md', '/tmp/outside/notes.txt']

function renderCard(overrides: Partial<Parameters<typeof CurrentTurnChangeCard>[0]> = {}) {
const onUndo = vi.fn()
const view = render(
<CurrentTurnChangeCard
sessionId="s1"
targetUserMessageId="user-1"
checkpoint={checkpoint(FILES)}
workDir="/repo"
error={null}
isUndoing={false}
isLatest
onUndo={onUndo}
{...overrides}
/>,
)
return { onUndo, ...view }
}

const card = () => screen.getByRole('region', { name: 'Turn changed files' })
const summary = () => within(card()).getByRole('button', { name: /files changed/ })
const fileRows = () => within(card()).queryAllByRole('button', { name: /^(Show|Hide) diff for / })

function stubViewport(mobile: boolean) {
vi.stubGlobal('matchMedia', (query: string) => ({ matches: mobile, media: query, addEventListener: vi.fn(), removeEventListener: vi.fn() }))
}

describe('CurrentTurnChangeCard', () => {
beforeEach(() => {
stubViewport(false)
})

afterEach(() => {
cleanup()
useSettingsStore.setState(useSettingsStore.getInitialState(), true)
vi.unstubAllGlobals()
vi.restoreAllMocks()
})

it('starts collapsed to one line with the number of files and the lines added and removed', () => {
renderCard()
expect(summary()).toHaveTextContent('3 files changed')
expect(summary()).toHaveTextContent('+418')
expect(summary()).toHaveTextContent('−0')
expect(summary()).toHaveAttribute('aria-expanded', 'false')
expect(fileRows()).toHaveLength(0)
expect(screen.queryByTestId('turn-change-files')).not.toBeInTheDocument()
})

it('lists the files when the line is clicked and hides them again on a second click', () => {
renderCard()
fireEvent.click(summary())
expect(summary()).toHaveAttribute('aria-expanded', 'true')
expect(fileRows().map((row) => row.getAttribute('aria-label'))).toEqual([
'Show diff for dc_artifacts/talk/slides/cover.html',
'Show diff for README.md',
'Show diff for /tmp/outside/notes.txt',
])
fireEvent.click(summary())
expect(fileRows()).toHaveLength(0)
})

it('keeps the undo button usable while collapsed, without opening the list', () => {
const { onUndo } = renderCard()
fireEvent.click(within(card()).getByRole('button', { name: 'Undo current turn changes' }))
expect(onUndo).toHaveBeenCalledOnce()
expect(fileRows()).toHaveLength(0)
expect(within(card()).getByRole('button', { name: 'Undo current turn changes' })).toHaveTextContent('Undo current turn')
})

it('shows the file name and, apart from it, the folder of each file', () => {
renderCard()
fireEvent.click(summary())
const [nested, atRoot, outside] = fileRows()
expect(within(nested!).getByText('cover.html')).toBeInTheDocument()
expect(within(nested!).getByText('dc_artifacts/talk/slides')).toBeInTheDocument()
expect(within(nested!).getByText('cover.html')).not.toBe(within(nested!).getByText('dc_artifacts/talk/slides'))
expect(within(nested!).queryByText('dc_artifacts/talk/slides/cover.html')).not.toBeInTheDocument()
expect(within(atRoot!).getByText('README.md').parentElement?.children).toHaveLength(1)
expect(within(outside!).getByText('/tmp/outside')).toBeInTheDocument()
})

it('loads the diff of a file when its row is clicked', async () => {
const getDiff = vi.spyOn(sessionsApi, 'getTurnCheckpointDiff').mockResolvedValue({ state: 'unavailable', error: 'No diff for this file.' } as never)
renderCard()
fireEvent.click(summary())
fireEvent.click(fileRows()[1]!)
expect(getDiff).toHaveBeenCalledWith('s1', 'user-1', '/repo/README.md', 0)
await waitFor(() => expect(within(card()).getByText('No diff for this file.')).toBeInTheDocument())
expect(within(card()).getByRole('button', { name: 'Hide diff for README.md' })).toHaveAttribute('aria-expanded', 'true')
})

it('shows the changed lines of a file without repeating its name above them', async () => {
const diff = ['--- a/README.md', '+++ b/README.md', '@@ -1 +1 @@', '-old title', '+new title', ''].join('\n')
vi.spyOn(sessionsApi, 'getTurnCheckpointDiff').mockResolvedValue({ state: 'ok', diff } as never)
renderCard()
fireEvent.click(summary())
fireEvent.click(fileRows()[1]!)
await waitFor(() => expect(card().querySelector('diffs-container')?.shadowRoot?.querySelector('[data-line-type="change-addition"]')).toBeTruthy())
const surface = card().querySelector('diffs-container')!.shadowRoot!
expect(surface.textContent).toContain('new title')
expect(surface.querySelector('[data-diffs-header]')).toBeNull()
expect(surface.textContent).not.toContain('README.md')
})

it('names the undo of an earlier turn differently and shows that it is running', () => {
renderCard({ isLatest: false, isUndoing: true })
const undo = within(card()).getByRole('button', { name: 'Rewind to before this turn' })
expect(undo).toBeDisabled()
expect(undo).toHaveTextContent('Undoing...')
})

it('shows why an undo failed even while collapsed', () => {
renderCard({ error: 'The checkpoint is gone.' })
expect(within(card()).getByText('The checkpoint is gone.')).toBeInTheDocument()
expect(fileRows()).toHaveLength(0)
})

it('shrinks the undo button to its icon on a phone, keeping its name', () => {
stubViewport(true)
renderCard()
const undo = within(card()).getByRole('button', { name: 'Undo current turn changes' })
expect(undo).toHaveTextContent('')
expect(undo).toHaveAttribute('title', 'Undo current turn')
expect(summary()).toHaveTextContent('3 files changed')
})

it('uses the language of the app', () => {
useSettingsStore.setState({ locale: 'zh' })
renderCard()
const region = screen.getByRole('region', { name: '轮次已更改文件' })
expect(within(region).getByRole('button', { name: /3 个文件已更改/ })).toBeInTheDocument()
expect(within(region).getByRole('button', { name: '撤销当前轮次变更' })).toHaveTextContent('撤销当前轮次')
})
})
Loading
Loading