fix(files): resolve workspace paths and add sandboxed HTML preview (#367)

* fix(files): resolve workspace paths and add sandboxed HTML preview

Accept workspace-absolute paths in the file service and return repo-relative paths for file reads and directory listings. Serve raw content under a CSP sandbox and preview HTML files in a sandboxed iframe with a raw toggle.

Resolve file-click paths from the session directory and repo local path, detect absolute and html/htm file references while ignoring URLs, accept the legacy filePath input key and filediff metadata, fix the file browser navigating into an initially selected directory, and use focus-visible rings across shared UI primitives.

* fix(files): address review feedback on navigation and path fallback

Key initial directory navigation to the initial selection so viewport changes do not reset it, and open the mobile preview from a separate effect.

Fall back to the legacy filePath input when path is empty, and cover both with regression tests.
This commit is contained in:
Chris Scott authored and GitHub committed 2026-09-28 22:27:18 -04:00
1 parent 5bd688de4b
commit 68b13c8e35
19 files changed
+307 -58

No files matched your search

@@ -377,6 +377,54 @@ describe('MessagePart', () => {
expect(screen.getByText('/test/file.txt')).toBeInTheDocument()
})
it('makes legacy filePath read, write, and filediff edit calls clickable', () => {
const onFileClick = vi.fn()
const legacy = (name: string, metadata: Record<string, unknown>) =>
toolPart(name, {
status: 'completed',
input: { filePath: `/test/${name}.html` },
content: [{ type: 'text', text: 'ok' }],
metadata,
})
renderWithProviders(
<>
<MessagePart part={legacy('read', {})} onFileClick={onFileClick} />
<MessagePart part={legacy('write', {})} onFileClick={onFileClick} />
<MessagePart
part={legacy('edit', { filediff: { file: '/test/edit.html', patch: '@@ -1 +1 @@\n-a\n+b', additions: 1, deletions: 1 } })}
onFileClick={onFileClick}
/>
</>,
)
fireEvent.click(screen.getByText('/test/read.html'))
fireEvent.click(screen.getByText('/test/write.html'))
fireEvent.click(screen.getByText('/test/edit.html'))
expect(onFileClick.mock.calls.map(([filePath]) => filePath)).toEqual(['/test/read.html', '/test/write.html', '/test/edit.html'])
expect(screen.getByText('+1')).toBeInTheDocument()
})
it('falls back to filePath when path is empty', () => {
const onFileClick = vi.fn()
renderWithProviders(
<MessagePart
part={toolPart('read', {
status: 'completed',
input: { path: '', filePath: '/test/fallback.html' },
content: [{ type: 'text', text: 'ok' }],
metadata: {},
})}
onFileClick={onFileClick}
/>,
)
fireEvent.click(screen.getByText('/test/fallback.html'))
expect(onFileClick).toHaveBeenCalledWith('/test/fallback.html')
})
it('renders every file of a multi-file patch with per-file links', () => {
const onFileClick = vi.fn()
renderWithProviders(