mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Merge branch 'main' into feat/walkthrough-plan-explain
Resolve ChangesWalkthroughSheet conflicts by keeping main's overview/paging model and the branch's source picker, per-stop status, and mechanical hunks.
This commit is contained in:
commit
b01d3ab6db
21 files changed
+390
-121
No files matched your search
@@ -34,6 +34,7 @@ type ReplayEventType = 'permission.asked' | 'form.created' | 'session.status'
|
||||
|
||||
const { RECONNECT_DELAY_MS, MAX_RECONNECT_DELAY_MS } = DEFAULTS.SSE
|
||||
const MULTILINE_PATTERN = /[\r\n]/
|
||||
const LOCATION_CATALOG_EVENT_TYPES = new Set(['command.updated', 'agent.updated', 'skill.updated'])
|
||||
|
||||
function serializeEnvelope(directory: string | null, payloadJson: string): string {
|
||||
return '{"directory":' + JSON.stringify(directory) + ',"payload":' + payloadJson + '}'
|
||||
@@ -434,7 +435,11 @@ class SSEAggregator {
|
||||
}
|
||||
|
||||
if (directory) {
|
||||
this.deliverEvent(directory, event, payloadJson)
|
||||
if (LOCATION_CATALOG_EVENT_TYPES.has(event.type)) {
|
||||
this.deliverResolvedEvent(directory, event, payloadJson)
|
||||
} else {
|
||||
this.deliverEvent(directory, event, payloadJson)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -797,3 +797,46 @@ describe('SSEAggregator directory-less session event routing', () => {
|
||||
expect(seen).toEqual([{ directory: '/r', type: 'session.execution.succeeded', sessionID: 'ses_fork' }])
|
||||
})
|
||||
})
|
||||
|
||||
describe('SSEAggregator location-scoped catalog event broadcast', () => {
|
||||
beforeEach(() => {
|
||||
sseAggregator.shutdown()
|
||||
sseAggregator.setPendingActionsFetcher(null)
|
||||
sseAggregator.setScheduledSessionsResolver(() => [])
|
||||
})
|
||||
|
||||
it.each(['command.updated', 'agent.updated', 'skill.updated'])(
|
||||
'broadcasts a location-scoped %s catalog event to every client without leaking other location-scoped events',
|
||||
(type) => {
|
||||
const subscribed = createCapturingClient()
|
||||
const unsubscribed = createCapturingClient()
|
||||
sseAggregator.addClient('catalog-a', subscribed.callback, subscribed.writeFrame, ['/repo-a'])
|
||||
sseAggregator.addClient('catalog-b', unsubscribed.callback, unsubscribed.writeFrame, [])
|
||||
|
||||
const seen: Array<{ directory: string; type: string }> = []
|
||||
sseAggregator.onEvent((directory, event) => {
|
||||
seen.push({ directory, type: event.type })
|
||||
})
|
||||
|
||||
emitRawEvent({ id: 'evt_catalog', type, location: { directory: '/repo-c' }, data: {} })
|
||||
|
||||
const expected = {
|
||||
directory: null,
|
||||
payload: { id: 'evt_catalog', created: 1, type, location: { directory: '/repo-c' }, data: {} },
|
||||
}
|
||||
expect(subscribed.frames.map(parseFrame)).toEqual([expected])
|
||||
expect(unsubscribed.frames.map(parseFrame)).toEqual([expected])
|
||||
expect(seen).toEqual([{ directory: '/repo-c', type }])
|
||||
|
||||
emitRawEvent({
|
||||
id: 'evt_status',
|
||||
type: 'session.status',
|
||||
location: { directory: '/repo-c' },
|
||||
data: { sessionID: 'ses-1', status: { type: 'busy' } },
|
||||
})
|
||||
|
||||
expect(subscribed.frames).toHaveLength(1)
|
||||
expect(unsubscribed.frames).toHaveLength(1)
|
||||
},
|
||||
)
|
||||
})
|
||||
@@ -197,11 +197,14 @@ function AppShell() {
|
||||
<EventProvider>
|
||||
<KeyboardShortcutsProvider>
|
||||
<GlobalShortcuts />
|
||||
<div ref={rootRef} className="flex h-dvh w-full min-w-0">
|
||||
<DesktopSidebar />
|
||||
<main className="flex-1 min-w-0 min-h-0 flex flex-col">
|
||||
<Outlet />
|
||||
</main>
|
||||
<div className="flex h-dvh w-full min-w-0 flex-col">
|
||||
<PwaUpdatePrompt />
|
||||
<div ref={rootRef} className="flex flex-1 min-h-0 w-full min-w-0">
|
||||
<DesktopSidebar />
|
||||
<main className="flex-1 min-w-0 min-h-0 flex flex-col">
|
||||
<Outlet />
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
<MobileTabBar />
|
||||
<MobileSheetHost />
|
||||
@@ -210,7 +213,6 @@ function AppShell() {
|
||||
<SettingsDialog />
|
||||
<HealthMonitor />
|
||||
<VersionNotifier />
|
||||
<PwaUpdatePrompt />
|
||||
<ThemedToaster />
|
||||
</KeyboardShortcutsProvider>
|
||||
</EventProvider>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { render, screen, fireEvent, act } from '@testing-library/react'
|
||||
import { PwaUpdatePrompt } from './PwaUpdatePrompt'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
onServiceWorkerUpdate: vi.fn(),
|
||||
offServiceWorkerUpdate: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/serviceWorker', () => ({
|
||||
onServiceWorkerUpdate: mocks.onServiceWorkerUpdate,
|
||||
offServiceWorkerUpdate: mocks.offServiceWorkerUpdate,
|
||||
}))
|
||||
|
||||
function triggerUpdate() {
|
||||
const callback = mocks.onServiceWorkerUpdate.mock.calls[0]?.[0]
|
||||
if (typeof callback !== 'function') throw new Error('update callback was not registered')
|
||||
act(() => callback())
|
||||
}
|
||||
|
||||
describe('PwaUpdatePrompt', () => {
|
||||
let reloadMock: ReturnType<typeof vi.fn>
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.onServiceWorkerUpdate.mockReset()
|
||||
mocks.offServiceWorkerUpdate.mockReset()
|
||||
reloadMock = vi.fn()
|
||||
Object.defineProperty(window, 'location', {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: { ...window.location, reload: reloadMock },
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('renders nothing until an update is signalled', () => {
|
||||
const { container } = render(<PwaUpdatePrompt />)
|
||||
|
||||
expect(container).toBeEmptyDOMElement()
|
||||
expect(screen.queryByRole('status')).toBeNull()
|
||||
})
|
||||
|
||||
it('shows a status bar with a Reload button when an update is signalled', () => {
|
||||
render(<PwaUpdatePrompt />)
|
||||
|
||||
triggerUpdate()
|
||||
|
||||
expect(screen.getByRole('status')).toHaveTextContent(
|
||||
'A new version of OpenCode Manager is available.',
|
||||
)
|
||||
expect(screen.getByRole('button', { name: 'Reload' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('reloads the page when Reload is clicked', () => {
|
||||
render(<PwaUpdatePrompt />)
|
||||
|
||||
triggerUpdate()
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Reload' }))
|
||||
|
||||
expect(reloadMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('unsubscribes from updates on unmount', () => {
|
||||
const { unmount } = render(<PwaUpdatePrompt />)
|
||||
|
||||
unmount()
|
||||
|
||||
expect(mocks.offServiceWorkerUpdate).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
@@ -1,21 +1,38 @@
|
||||
import { useEffect } from 'react'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { RefreshCw } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { onServiceWorkerUpdate, offServiceWorkerUpdate } from '@/lib/serviceWorker'
|
||||
|
||||
export function PwaUpdatePrompt() {
|
||||
const [visible, setVisible] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
onServiceWorkerUpdate(() => {
|
||||
showToast.info('New build deployed', {
|
||||
description: 'Refresh to load the latest changes.',
|
||||
action: {
|
||||
label: 'Refresh',
|
||||
onClick: () => window.location.reload(),
|
||||
},
|
||||
duration: Infinity,
|
||||
})
|
||||
})
|
||||
onServiceWorkerUpdate(() => setVisible(true))
|
||||
return () => offServiceWorkerUpdate()
|
||||
}, [])
|
||||
|
||||
return null
|
||||
if (!visible) return null
|
||||
|
||||
return (
|
||||
<div
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className="w-full shrink-0 bg-primary pt-safe text-primary-foreground"
|
||||
>
|
||||
<div className="flex flex-wrap items-center justify-center gap-3 px-4 py-2">
|
||||
<RefreshCw className="h-4 w-4 shrink-0" aria-hidden="true" />
|
||||
<span className="text-sm font-medium">
|
||||
A new version of OpenCode Manager is available.
|
||||
</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
onClick={() => window.location.reload()}
|
||||
>
|
||||
Reload
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -70,6 +70,18 @@ describe('PromptSuggestions', () => {
|
||||
expect(handlers.onSelect).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('omits the icon for commands but keeps it for other kinds', () => {
|
||||
renderList({
|
||||
items: [
|
||||
{ key: 'review', value: 'review', kind: 'command', label: '/review', ranges: [] },
|
||||
{ key: 'build', value: 'build', kind: 'agent', label: '@build', ranges: [] },
|
||||
],
|
||||
})
|
||||
|
||||
expect(rowButton('/review').querySelector('svg')).toBeNull()
|
||||
expect(rowButton('@build').querySelector('svg')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders nothing without items', () => {
|
||||
renderList({ items: [] })
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useEffect, useLayoutEffect, useRef, useState, type ReactNode, type RefObject } from 'react'
|
||||
import { Bot, Command, FileText, Sparkles, Play } from 'lucide-react'
|
||||
import { Bot, FileText, Sparkles, Play, type LucideIcon } from 'lucide-react'
|
||||
import { SWIPE_COMMIT_DISTANCE, useTouchTapSelect } from '@/hooks/useTouchTapSelect'
|
||||
import type { MatchRange } from '@/lib/fuzzyMatch'
|
||||
|
||||
@@ -28,8 +28,7 @@ interface PromptSuggestionsProps<T> {
|
||||
const TAKEOVER_TOP_GAP_PX = 8
|
||||
const TAKEOVER_MIN_HEIGHT_PX = 160
|
||||
|
||||
const KIND_ICONS: Record<SuggestionKind, typeof Command> = {
|
||||
command: Command,
|
||||
const KIND_ICONS: Partial<Record<SuggestionKind, LucideIcon>> = {
|
||||
agent: Bot,
|
||||
skill: Sparkles,
|
||||
file: FileText,
|
||||
@@ -111,12 +110,14 @@ export function PromptSuggestions<T>({
|
||||
: takeover ? 'bg-background border-transparent hover:bg-muted text-foreground' : 'hover:bg-muted text-foreground'
|
||||
}`}
|
||||
>
|
||||
<span className={takeover
|
||||
? `grid place-items-center w-8 h-8 flex-shrink-0 rounded-lg border ${isSelected ? 'bg-primary text-primary-foreground border-primary' : 'bg-muted border-border text-muted-foreground'}`
|
||||
: 'mt-0.5 flex-shrink-0 opacity-80'}
|
||||
>
|
||||
<Icon className="w-4 h-4" />
|
||||
</span>
|
||||
{Icon && (
|
||||
<span className={takeover
|
||||
? `grid place-items-center w-8 h-8 flex-shrink-0 rounded-lg border ${isSelected ? 'bg-primary text-primary-foreground border-primary' : 'bg-muted border-border text-muted-foreground'}`
|
||||
: 'mt-0.5 flex-shrink-0 opacity-80'}
|
||||
>
|
||||
<Icon className="w-4 h-4" />
|
||||
</span>
|
||||
)}
|
||||
<span className="flex-1 min-w-0">
|
||||
<span className={`block font-mono font-medium truncate ${takeover ? 'text-base' : 'text-sm'}`}>
|
||||
{renderHighlighted(item.label, item.ranges)}
|
||||
|
||||
@@ -136,13 +136,14 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
Element.prototype.setPointerCapture ??= () => {}
|
||||
Element.prototype.releasePointerCapture ??= () => {}
|
||||
Element.prototype.scrollIntoView ??= () => {}
|
||||
Element.prototype.scrollTo ??= () => {}
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('generates a walkthrough and renders the summary and first stop', async () => {
|
||||
it('generates a walkthrough and opens on the overview page', async () => {
|
||||
const user = userEvent.setup()
|
||||
let generated = false
|
||||
mocks.getChangeWalkthrough.mockImplementation(async () =>
|
||||
@@ -161,33 +162,73 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
expect(mocks.generateChangeWalkthrough).toHaveBeenCalledWith('ses_1', { source: { kind: 'session' } })
|
||||
})
|
||||
expect(await screen.findByText('This change adds a greeting.')).toBeInTheDocument()
|
||||
expect(screen.getByText('Stop 1 of 2')).toBeInTheDocument()
|
||||
expect(screen.getByText('src/greet.ts')).toBeInTheDocument()
|
||||
expect(screen.getByText('const a = 2')).toBeInTheDocument()
|
||||
expect(screen.queryByText('src/main.ts')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Overview')).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '1. Add the greeting' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '2. Wire it up' })).toBeInTheDocument()
|
||||
expect(screen.queryByText('src/greet.ts')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('assets/logo.png — binary file')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('moves through the stops with the navigator in order', async () => {
|
||||
it('opens a stop from the overview list without the summary or list', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.getChangeWalkthrough.mockResolvedValue(state())
|
||||
renderSheet()
|
||||
|
||||
expect(await screen.findByText('Stop 1 of 2')).toBeInTheDocument()
|
||||
expect(screen.getByText('src/greet.ts')).toBeInTheDocument()
|
||||
await user.click(await screen.findByRole('button', { name: '2. Wire it up' }))
|
||||
|
||||
expect(await screen.findByText('2 of 2')).toBeInTheDocument()
|
||||
expect(screen.getByText('src/main.ts')).toBeInTheDocument()
|
||||
expect(screen.queryByText('This change adds a greeting.')).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: '1. Add the greeting' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('jumps between pages from the header dropdown', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.getChangeWalkthrough.mockResolvedValue(state())
|
||||
renderSheet()
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: '1. Add the greeting' }))
|
||||
expect(await screen.findByText('1 of 2')).toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Jump to page' }))
|
||||
await user.click(await screen.findByRole('menuitemradio', { name: '2. Wire it up' }))
|
||||
expect(await screen.findByText('2 of 2')).toBeInTheDocument()
|
||||
expect(screen.getByText('src/main.ts')).toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Jump to page' }))
|
||||
await user.click(await screen.findByRole('menuitemradio', { name: 'Overview' }))
|
||||
expect(await screen.findByText('This change adds a greeting.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('moves through the overview and stops with the navigator in order', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.getChangeWalkthrough.mockResolvedValue(state())
|
||||
renderSheet()
|
||||
|
||||
expect(await screen.findByText('Overview')).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: /previous/i })).toBeDisabled()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /next/i }))
|
||||
|
||||
expect(await screen.findByText('Stop 2 of 2')).toBeInTheDocument()
|
||||
expect(await screen.findByText('1 of 2')).toBeInTheDocument()
|
||||
expect(screen.getByText('src/greet.ts')).toBeInTheDocument()
|
||||
expect(screen.getByText('const a = 2')).toBeInTheDocument()
|
||||
expect(screen.queryByText('This change adds a greeting.')).not.toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /next/i }))
|
||||
|
||||
expect(await screen.findByText('2 of 2')).toBeInTheDocument()
|
||||
expect(screen.getByText('src/main.ts')).toBeInTheDocument()
|
||||
expect(screen.queryByText('src/greet.ts')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('truncated')).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: /next/i })).toBeDisabled()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /previous/i }))
|
||||
expect(await screen.findByText('1 of 2')).toBeInTheDocument()
|
||||
|
||||
expect(await screen.findByText('Stop 1 of 2')).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: /previous/i }))
|
||||
expect(await screen.findByText('Overview')).toBeInTheDocument()
|
||||
expect(screen.getByText('This change adds a greeting.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('updates a stale walkthrough incrementally', async () => {
|
||||
@@ -213,7 +254,7 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
mocks.generateChangeWalkthrough.mockResolvedValue(state())
|
||||
renderSheet()
|
||||
|
||||
await screen.findByText('Stop 1 of 2')
|
||||
await screen.findByText('Overview')
|
||||
await user.click(screen.getByRole('button', { name: 'Regenerate walkthrough' }))
|
||||
|
||||
await waitFor(() => {
|
||||
@@ -354,6 +395,27 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
expect(await screen.findByRole('button', { name: 'Generate walkthrough' })).toBeVisible()
|
||||
})
|
||||
|
||||
it('scrolls back to the top of the overview when a walkthrough is regenerated', async () => {
|
||||
const user = userEvent.setup()
|
||||
const scrollTo = vi.spyOn(Element.prototype, 'scrollTo')
|
||||
let createdAt = 1
|
||||
mocks.getChangeWalkthrough.mockImplementation(async () => state({ walkthrough: { ...walkthrough, createdAt } }))
|
||||
mocks.generateChangeWalkthrough.mockImplementation(async () => {
|
||||
createdAt = 2
|
||||
return state({ walkthrough: { ...walkthrough, createdAt } })
|
||||
})
|
||||
renderSheet()
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: '1. Add the greeting' }))
|
||||
expect(await screen.findByText('1 of 2')).toBeInTheDocument()
|
||||
|
||||
scrollTo.mockClear()
|
||||
await user.click(screen.getByRole('button', { name: 'Regenerate walkthrough' }))
|
||||
|
||||
await waitFor(() => expect(scrollTo).toHaveBeenCalledWith({ top: 0 }))
|
||||
expect(await screen.findByText('Overview')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows progress while the server is generating instead of the generate button', async () => {
|
||||
mocks.getChangeWalkthrough.mockResolvedValue(state({ walkthrough: null, generating: true }))
|
||||
renderSheet()
|
||||
@@ -363,6 +425,7 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
})
|
||||
|
||||
it('renders ready and pending stops while generating', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.getChangeWalkthrough.mockResolvedValue(
|
||||
state({
|
||||
generating: true,
|
||||
@@ -377,9 +440,12 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
)
|
||||
renderSheet()
|
||||
|
||||
expect(await screen.findByText('Introduces the greeting helper.')).toBeInTheDocument()
|
||||
expect(screen.getByText(/1 of 2 stops explained/)).toBeInTheDocument()
|
||||
expect(await screen.findByText(/1 of 2 stops explained/)).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: '1. Add the greeting' })).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Explaining')).toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: '1. Add the greeting' }))
|
||||
expect(await screen.findByText('Introduces the greeting helper.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('retries unexplained stops', async () => {
|
||||
@@ -398,6 +464,7 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
mocks.generateChangeWalkthrough.mockResolvedValue(state({ generating: true }))
|
||||
renderSheet()
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: /1\. Add the greeting/ }))
|
||||
expect(await screen.findByText('This stop could not be explained.')).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Retry unexplained stops' }))
|
||||
|
||||
@@ -484,9 +551,11 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
})
|
||||
|
||||
it('renders mechanical files as a compact summary list with counts and diff text for budgeted hunks', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.getChangeWalkthrough.mockResolvedValue(state({ walkthrough: mechanicalWalkthrough }))
|
||||
renderSheet()
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: '1. Mechanical changes' }))
|
||||
expect(
|
||||
await screen.findByRole('list', { name: 'Mechanical file summaries' }),
|
||||
).toBeInTheDocument()
|
||||
@@ -501,6 +570,7 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
})
|
||||
|
||||
it('renders a stored mechanical stop whose hunks predate hunk counts', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.getChangeWalkthrough.mockResolvedValue(
|
||||
state({
|
||||
walkthrough: {
|
||||
@@ -531,6 +601,7 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
)
|
||||
renderSheet()
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: '1. Mechanical changes' }))
|
||||
expect(await screen.findByText('pnpm-lock.yaml')).toBeInTheDocument()
|
||||
expect(screen.getByText('new-lock')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('list', { name: 'Mechanical file summaries' })).not.toBeInTheDocument()
|
||||
@@ -550,9 +621,12 @@ describe('ChangesWalkthroughSheet', () => {
|
||||
},
|
||||
}),
|
||||
)
|
||||
const user = userEvent.setup()
|
||||
const { container } = renderSheet()
|
||||
|
||||
expect(await screen.findByText(/Summary/)).toBeInTheDocument()
|
||||
expect(container.querySelector('iframe')).toBeNull()
|
||||
await user.click(screen.getByRole('button', { name: /next/i }))
|
||||
expect(await screen.findByText(/Explanation/)).toBeInTheDocument()
|
||||
expect(container.querySelector('iframe')).toBeNull()
|
||||
expect(container.querySelector('script')).toBeNull()
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import { createContext, memo, useCallback, useContext, useEffect, useRef, useState } from 'react'
|
||||
import type { ReactNode, RefObject } from 'react'
|
||||
import { ChevronLeft, ChevronRight, Loader2, RefreshCw } from 'lucide-react'
|
||||
import { ChevronDown, ChevronLeft, ChevronRight, Loader2, RefreshCw } from 'lucide-react'
|
||||
import { SideDrawer, SideDrawerHeader } from '@/components/ui/side-drawer'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
@@ -10,7 +18,6 @@ import { DiffLines } from '@/components/file-browser/DiffLines'
|
||||
import { ScheduleRunMarkdown } from '@/components/schedules/ScheduleRunMarkdown'
|
||||
import { useChangeWalkthrough, useGenerateChangeWalkthrough } from '@/hooks/useChangeWalkthrough'
|
||||
import { GIT_STATUS_COLORS, GIT_STATUS_LABELS } from '@/lib/git-status-styles'
|
||||
import { cn } from '@/lib/utils'
|
||||
import {
|
||||
DEFAULT_WALKTHROUGH_SOURCE,
|
||||
describeWalkthroughSource,
|
||||
@@ -121,11 +128,11 @@ interface ChangesWalkthroughContextValue {
|
||||
generate: () => void
|
||||
regenerate: () => void
|
||||
stops: WalkthroughStop[]
|
||||
stopIndex: number
|
||||
stopIndex: number | null
|
||||
selectedStop: WalkthroughStop | null
|
||||
selectedHunks: WalkthroughHunk[]
|
||||
selectStop: (index: number) => void
|
||||
detailRef: RefObject<HTMLDivElement | null>
|
||||
selectStop: (index: number | null) => void
|
||||
scrollRef: RefObject<HTMLDivElement | null>
|
||||
failedStopCount: number
|
||||
source: WalkthroughSource
|
||||
setSource: (source: WalkthroughSource) => void
|
||||
@@ -245,8 +252,8 @@ export function ChangesWalkthroughProvider({ sessionId, active, children }: Chan
|
||||
const stateQuery = useChangeWalkthrough(sessionId, active, source)
|
||||
const generate = useGenerateChangeWalkthrough(sessionId, source)
|
||||
const resetGenerate = generate.reset
|
||||
const [stopIndex, setStopIndex] = useState(0)
|
||||
const detailRef = useRef<HTMLDivElement>(null)
|
||||
const [stopIndex, setStopIndex] = useState<number | null>(null)
|
||||
const scrollRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const state = stateQuery.data
|
||||
const walkthrough = state?.walkthrough ?? null
|
||||
@@ -265,13 +272,14 @@ export function ChangesWalkthroughProvider({ sessionId, active, children }: Chan
|
||||
}, [active, sessionId, sourceKey, resetGenerate])
|
||||
|
||||
useEffect(() => {
|
||||
setStopIndex(0)
|
||||
setStopIndex(null)
|
||||
scrollRef.current?.scrollTo?.({ top: 0 })
|
||||
}, [active, sessionId, sourceKey, walkthrough?.createdAt])
|
||||
|
||||
const hunksById = new Map(walkthrough?.hunks.map((hunk) => [hunk.id, hunk]) ?? [])
|
||||
const stops = walkthrough?.stops ?? []
|
||||
const clampedIndex = stops.length > 0 ? Math.min(stopIndex, stops.length - 1) : 0
|
||||
const selectedStop = stops[clampedIndex] ?? null
|
||||
const clampedIndex = stopIndex === null || stops.length === 0 ? null : Math.min(stopIndex, stops.length - 1)
|
||||
const selectedStop = clampedIndex === null ? null : stops[clampedIndex] ?? null
|
||||
const selectedHunks = (selectedStop?.hunkIds ?? [])
|
||||
.map((id) => hunksById.get(id))
|
||||
.filter((hunk): hunk is WalkthroughHunk => hunk !== undefined)
|
||||
@@ -280,9 +288,9 @@ export function ChangesWalkthroughProvider({ sessionId, active, children }: Chan
|
||||
(stop) => stop.status === 'failed' || (stop.status === 'pending' && !generating),
|
||||
).length
|
||||
|
||||
const selectStop = useCallback((index: number) => {
|
||||
const selectStop = useCallback((index: number | null) => {
|
||||
setStopIndex(index)
|
||||
detailRef.current?.scrollIntoView?.({ block: 'start', behavior: 'smooth' })
|
||||
scrollRef.current?.scrollTo?.({ top: 0 })
|
||||
}, [])
|
||||
|
||||
const value: ChangesWalkthroughContextValue = {
|
||||
@@ -299,7 +307,7 @@ export function ChangesWalkthroughProvider({ sessionId, active, children }: Chan
|
||||
selectedStop,
|
||||
selectedHunks,
|
||||
selectStop,
|
||||
detailRef,
|
||||
scrollRef,
|
||||
failedStopCount,
|
||||
source,
|
||||
setSource,
|
||||
@@ -315,7 +323,7 @@ export function ChangesWalkthroughProvider({ sessionId, active, children }: Chan
|
||||
return <ChangesWalkthroughContext.Provider value={value}>{children}</ChangesWalkthroughContext.Provider>
|
||||
}
|
||||
|
||||
/** Previous/next stop controls for the walkthrough chrome; renders nothing until a walkthrough has stops. */
|
||||
/** Previous/next page controls (overview, then each stop) for the walkthrough chrome; renders nothing until a walkthrough has stops. */
|
||||
export const ChangesWalkthroughNav = memo(function ChangesWalkthroughNav() {
|
||||
const { stops, stopIndex, selectStop } = useChangesWalkthrough()
|
||||
|
||||
@@ -327,20 +335,39 @@ export const ChangesWalkthroughNav = memo(function ChangesWalkthroughNav() {
|
||||
variant="outline"
|
||||
size="icon-sm"
|
||||
aria-label="Previous stop"
|
||||
onClick={() => selectStop(stopIndex - 1)}
|
||||
disabled={stopIndex === 0}
|
||||
onClick={() => selectStop(stopIndex === null || stopIndex === 0 ? null : stopIndex - 1)}
|
||||
disabled={stopIndex === null}
|
||||
>
|
||||
<ChevronLeft />
|
||||
</Button>
|
||||
<span className="whitespace-nowrap text-xs text-muted-foreground">
|
||||
Stop {stopIndex + 1} of {stops.length}
|
||||
</span>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="sm" aria-label="Jump to page" className="h-7 gap-1 px-2 text-xs text-muted-foreground">
|
||||
{stopIndex === null ? 'Overview' : `${stopIndex + 1} of ${stops.length}`}
|
||||
<ChevronDown className="h-3 w-3" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="max-h-[60vh] w-72 overflow-y-auto">
|
||||
<DropdownMenuRadioGroup
|
||||
value={stopIndex === null ? 'overview' : String(stopIndex)}
|
||||
onValueChange={(value) => selectStop(value === 'overview' ? null : Number(value))}
|
||||
>
|
||||
<DropdownMenuRadioItem value="overview">Overview</DropdownMenuRadioItem>
|
||||
<DropdownMenuSeparator />
|
||||
{stops.map((stop, index) => (
|
||||
<DropdownMenuRadioItem key={index} value={String(index)}>
|
||||
{index + 1}. {stop.title}
|
||||
</DropdownMenuRadioItem>
|
||||
))}
|
||||
</DropdownMenuRadioGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon-sm"
|
||||
aria-label="Next stop"
|
||||
onClick={() => selectStop(stopIndex + 1)}
|
||||
disabled={stopIndex >= stops.length - 1}
|
||||
onClick={() => selectStop(stopIndex === null ? 0 : stopIndex + 1)}
|
||||
disabled={stopIndex !== null && stopIndex >= stops.length - 1}
|
||||
>
|
||||
<ChevronRight />
|
||||
</Button>
|
||||
@@ -378,11 +405,10 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() {
|
||||
contextLimitFiles,
|
||||
generate,
|
||||
stops,
|
||||
stopIndex,
|
||||
selectedStop,
|
||||
selectedHunks,
|
||||
selectStop,
|
||||
detailRef,
|
||||
scrollRef,
|
||||
failedStopCount,
|
||||
source,
|
||||
sourcePending,
|
||||
@@ -402,7 +428,7 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-0 flex-1 space-y-4 overflow-y-auto p-4">
|
||||
<div ref={scrollRef} className="min-h-0 flex-1 space-y-4 overflow-y-auto p-4">
|
||||
<WalkthroughSourcePicker />
|
||||
|
||||
{error ? (
|
||||
@@ -459,44 +485,9 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() {
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<ScheduleRunMarkdown content={walkthrough.summary} />
|
||||
|
||||
{stops.length > 0 ? (
|
||||
<ol className="space-y-0.5">
|
||||
{stops.map((stop, index) => (
|
||||
<li key={stop.id}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => selectStop(index)}
|
||||
aria-current={index === stopIndex}
|
||||
className={cn(
|
||||
'w-full rounded-md px-2 py-1 text-left text-sm',
|
||||
index === stopIndex
|
||||
? 'bg-accent/40 font-medium text-foreground'
|
||||
: 'text-muted-foreground hover:bg-accent/20',
|
||||
)}
|
||||
>
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="min-w-0 flex-1 truncate">
|
||||
{index + 1}. {stop.title}
|
||||
</span>
|
||||
{stop.status === 'pending' && generating ? (
|
||||
<Loader2 className="h-3.5 w-3.5 shrink-0 animate-spin" aria-label="Explaining" />
|
||||
) : stop.status === 'failed' || stop.status === 'pending' ? (
|
||||
<span className="shrink-0 text-xs text-muted-foreground">not explained</span>
|
||||
) : null}
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
) : null}
|
||||
|
||||
{selectedStop ? (
|
||||
<div ref={detailRef} className="scroll-mt-4 space-y-3 border-t border-border pt-4">
|
||||
<h3 className="text-sm font-semibold text-foreground">
|
||||
{stopIndex + 1}. {selectedStop.title}
|
||||
</h3>
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-sm font-semibold text-foreground">{selectedStop.title}</h3>
|
||||
{selectedStop.status === 'ready' ? (
|
||||
<ScheduleRunMarkdown content={selectedStop.explanation} />
|
||||
) : (
|
||||
@@ -522,9 +513,38 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() {
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
) : (
|
||||
<>
|
||||
<ScheduleRunMarkdown content={walkthrough.summary} />
|
||||
|
||||
{walkthrough.omittedFiles.length > 0 ? <OmittedFiles files={walkthrough.omittedFiles} /> : null}
|
||||
{stops.length > 0 ? (
|
||||
<ol className="space-y-0.5">
|
||||
{stops.map((stop, index) => (
|
||||
<li key={stop.id}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => selectStop(index)}
|
||||
className="w-full rounded-md px-2 py-1 text-left text-sm text-muted-foreground hover:bg-accent/20 hover:text-foreground"
|
||||
>
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="min-w-0 flex-1 truncate">
|
||||
{index + 1}. {stop.title}
|
||||
</span>
|
||||
{stop.status === 'pending' && generating ? (
|
||||
<Loader2 className="h-3.5 w-3.5 shrink-0 animate-spin" aria-label="Explaining" />
|
||||
) : stop.status === 'failed' || stop.status === 'pending' ? (
|
||||
<span className="shrink-0 text-xs text-muted-foreground">not explained</span>
|
||||
) : null}
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
) : null}
|
||||
|
||||
{walkthrough.omittedFiles.length > 0 ? <OmittedFiles files={walkthrough.omittedFiles} /> : null}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -25,7 +25,7 @@ export function Sidebar({
|
||||
return (
|
||||
<aside
|
||||
className={cn(
|
||||
'relative z-20 flex-shrink-0 border-r border-border bg-card/50 backdrop-blur-sm h-dvh flex flex-col pt-safe pb-safe transition-[width] duration-200',
|
||||
'relative z-20 flex-shrink-0 border-r border-border bg-card/50 backdrop-blur-sm h-full flex flex-col pt-safe pb-safe transition-[width] duration-200',
|
||||
collapsed ? collapsedWidthClass : widthClass,
|
||||
className
|
||||
)}
|
||||
|
||||
@@ -130,6 +130,27 @@ describe('useCommands', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('loads commands for a newly selected directory even when queries have a stale time', async () => {
|
||||
vi.mocked(listCommands).mockImplementation(async (directory) => [
|
||||
{ name: directory === '/repo-b' ? 'from-b' : 'from-a', description: '' },
|
||||
])
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: 60_000 } } })
|
||||
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
||||
)
|
||||
|
||||
const { result, rerender } = renderHook(({ directory }) => useCommands({ directory }), {
|
||||
wrapper,
|
||||
initialProps: { directory: '/repo-a' },
|
||||
})
|
||||
await waitFor(() => expect(result.current.findCommand('from-a')).toBeDefined())
|
||||
|
||||
rerender({ directory: '/repo-b' })
|
||||
|
||||
await waitFor(() => expect(result.current.findCommand('from-b')).toBeDefined())
|
||||
expect(listCommands).toHaveBeenCalledWith('/repo-b')
|
||||
})
|
||||
|
||||
it('finds only exact command names, ignoring case', () => {
|
||||
const { result } = renderHook(() => useCommands({ enabled: false }), { wrapper: createWrapper() })
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ export function useCommands(options: UseCommandsOptions = {}) {
|
||||
},
|
||||
enabled,
|
||||
initialData: SORTED_BUILTIN_COMMANDS,
|
||||
initialDataUpdatedAt: 0,
|
||||
})
|
||||
|
||||
const searchCommands = useCallback((query: string) => rankByMatch(commands, query, {
|
||||
|
||||
@@ -53,8 +53,8 @@ export function AssistantRedirect() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-dvh max-h-dvh min-w-0">
|
||||
<div className="flex-1 min-w-0 h-dvh max-h-dvh overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-0">
|
||||
<div className="flex h-full max-h-full min-w-0">
|
||||
<div className="flex-1 min-w-0 h-full max-h-full overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-0">
|
||||
<Header>
|
||||
<Header.BackButton to="/" />
|
||||
<Header.Title>Assistant</Header.Title>
|
||||
|
||||
@@ -386,7 +386,7 @@ export function GlobalSchedules() {
|
||||
const selectedRunLookupError = selectedRunMissing && selectedRunError && selectedRun === null
|
||||
|
||||
return (
|
||||
<div className="h-dvh max-h-dvh overflow-hidden bg-background flex flex-col">
|
||||
<div className="h-full max-h-full overflow-hidden bg-background flex flex-col">
|
||||
<Header>
|
||||
<Header.BackButton to="/" />
|
||||
<div className="min-w-0 flex-1 px-3">
|
||||
|
||||
@@ -80,8 +80,8 @@ export function Login() {
|
||||
const hasCredentials = config.enabledProviders.includes('credentials')
|
||||
|
||||
return (
|
||||
<div className="h-dvh flex flex-col items-center justify-center bg-gradient-to-br from-background via-background to-background p-4">
|
||||
<div className="w-full max-w-sm space-y-6">
|
||||
<div className="h-full overflow-y-auto bg-gradient-to-br from-background via-background to-background p-4">
|
||||
<div className="mx-auto flex min-h-full w-full max-w-sm flex-col justify-center space-y-6">
|
||||
<div className="flex flex-col items-center space-y-2">
|
||||
<img
|
||||
src={theme === 'light' ? "/opencode-wordmark-light.svg" : "/opencode-wordmark-dark.svg"}
|
||||
|
||||
@@ -53,8 +53,8 @@ export function Register() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-dvh flex flex-col items-center justify-center bg-gradient-to-br from-background via-background to-background p-4">
|
||||
<div className="w-full max-w-sm space-y-6">
|
||||
<div className="h-full overflow-y-auto bg-gradient-to-br from-background via-background to-background p-4">
|
||||
<div className="mx-auto flex min-h-full w-full max-w-sm flex-col justify-center space-y-6">
|
||||
<div className="flex flex-col items-center space-y-2">
|
||||
<img
|
||||
src={theme === 'light' ? "/opencode-wordmark-light.svg" : "/opencode-wordmark-dark.svg"}
|
||||
|
||||
@@ -216,9 +216,9 @@ export function RepoDetail() {
|
||||
const isWorktree = repo.isWorktree || false;
|
||||
|
||||
return (
|
||||
<div className="flex h-dvh max-h-dvh min-w-0">
|
||||
<div className="flex h-full max-h-full min-w-0">
|
||||
<div
|
||||
className="flex-1 min-w-0 h-dvh max-h-dvh overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-0"
|
||||
className="flex-1 min-w-0 h-full max-h-full overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-0"
|
||||
>
|
||||
<Header>
|
||||
<div className="flex items-center gap-2 sm:gap-3 min-w-0 flex-1">
|
||||
|
||||
@@ -24,8 +24,8 @@ export function Repos() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex h-dvh max-h-dvh min-w-0">
|
||||
<div className="flex-1 min-w-0 h-dvh max-h-dvh overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col">
|
||||
<div className="flex h-full max-h-full min-w-0">
|
||||
<div className="flex-1 min-w-0 h-full max-h-full overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col">
|
||||
<Header>
|
||||
<div className="flex items-center gap-3">
|
||||
<Header.Title logo>OpenCode</Header.Title>
|
||||
|
||||
@@ -40,7 +40,7 @@ export function Schedules() {
|
||||
const backHref = getReturnToPath(location.search, scheduleTarget.backHref)
|
||||
|
||||
return (
|
||||
<div className="h-dvh max-h-dvh overflow-hidden bg-background flex flex-col">
|
||||
<div className="h-full max-h-full overflow-hidden bg-background flex flex-col">
|
||||
<Header>
|
||||
<Header.BackButton to={backHref} />
|
||||
<div className="min-w-0 flex-1 px-3">
|
||||
|
||||
@@ -659,7 +659,7 @@ export function SessionDetail() {
|
||||
|
||||
return (
|
||||
<div
|
||||
className="h-dvh max-h-dvh overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col"
|
||||
className="h-full max-h-full overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col"
|
||||
>
|
||||
<div
|
||||
data-testid="session-header-region"
|
||||
|
||||
@@ -46,8 +46,8 @@ export function Setup() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="h-dvh flex flex-col items-center justify-center bg-gradient-to-br from-background via-background to-background p-4">
|
||||
<div className="w-full max-w-sm space-y-6">
|
||||
<div className="h-full overflow-y-auto bg-gradient-to-br from-background via-background to-background p-4">
|
||||
<div className="mx-auto flex min-h-full w-full max-w-sm flex-col justify-center space-y-6">
|
||||
<div className="flex flex-col items-center space-y-2">
|
||||
<img
|
||||
src={theme === 'light' ? "/opencode-wordmark-light.svg" : "/opencode-wordmark-dark.svg"}
|
||||
|
||||
Reference in new issue
Block a user