Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(ui): keep the file extension on Download

Sanil6a6ae29cc5a6
diff --git a/app/src/features/conversations/aui/ArtifactPreviewPanel.markdown.test.tsx b/app/src/features/conversations/aui/ArtifactPreviewPanel.markdown.test.tsx
index 3578603894..6396eeb6c8 100644
--- a/app/src/features/conversations/aui/ArtifactPreviewPanel.markdown.test.tsx
+++ b/app/src/features/conversations/aui/ArtifactPreviewPanel.markdown.test.tsx
@@ -8,7 +8,7 @@ import chatRuntimeReducer, {
openArtifact,
upsertArtifactReadyForThread,
} from '../../../store/chatRuntimeSlice';
-import { ArtifactPreviewPanel } from './ArtifactPreviewPanel';
+import { ArtifactPreviewPanel, fileExtension } from './ArtifactPreviewPanel';
vi.mock('../../../services/coreRpcClient', () => ({ callCoreRpc: vi.fn() }));
@@ -120,3 +120,12 @@ describe('ArtifactPreviewPanel — preview rendering by kind (#1535)', () => {
expect(screen.queryByRole('heading')).toBeNull();
});
});
+
+describe('fileExtension', () => {
+ it('reads the extension from the file name only', () => {
+ expect(fileExtension('/files/release-v1.2.md')).toBe('md');
+ expect(fileExtension('/files.d/notes')).toBe('');
+ expect(fileExtension('C:\\Users\\me\\Files\\deck.pptx')).toBe('pptx');
+ expect(fileExtension(undefined)).toBe('');
+ });
+});
diff --git a/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx b/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx
index aac707ab20..b58237fef0 100644
--- a/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx
+++ b/app/src/features/conversations/aui/ArtifactPreviewPanel.tsx
@@ -419,13 +419,19 @@ async function saveArtifactAs(
artifact: ArtifactSnapshot,
t: (key: string) => string
): Promise<string | null> {
- const extension = artifact.path?.split('.').pop() ?? '';
+ const extension = fileExtension(artifact.path);
const outcome = await saveArtifactViaDialog(artifact.artifactId, artifact.title, extension);
if (outcome.ok || outcome.code === 'CANCELLED') return null;
console.warn('[ArtifactPreviewPanel] download failed:', outcome.code, outcome.error);
return t(`chat.files.error.${(outcome.code ?? 'download_failed').toLowerCase()}`);
}
+/** The extension of the file a path names (`'md'` for `.../notes.md`), or `''`. */
+export function fileExtension(path: string | undefined): string {
+ const name = path?.split(/[\\/]/).pop() ?? '';
+ return /\.([^.]+)$/.exec(name)?.[1] ?? '';
+}
+
type AutosaveState = 'saved' | 'pending' | 'saving' | 'error';
/**
diff --git a/app/src/services/__tests__/artifactDownloadService.test.ts b/app/src/services/__tests__/artifactDownloadService.test.ts
index 8a539beb4a..8b5688824e 100644
--- a/app/src/services/__tests__/artifactDownloadService.test.ts
+++ b/app/src/services/__tests__/artifactDownloadService.test.ts
@@ -301,6 +301,19 @@ describe('downloadArtifact', () => {
});
});
+ it('appends the extension to a title that only looks like it has one', async () => {
+ vi.mocked(callCoreRpc).mockResolvedValueOnce({
+ absolute_path: '/workspace/files/release-v1.2.md',
+ meta: { title: 'Release v1.2' },
+ });
+ hoisted.invoke.mockResolvedValueOnce('/dest/Release v1.2.md');
+ await downloadArtifact('art-1', 'Release v1.2', 'md');
+ expect(hoisted.invoke).toHaveBeenCalledWith('download_artifact_to_downloads', {
+ artifactId: 'art-1',
+ filename: 'Release v1.2.md',
+ });
+ });
+
it('does NOT double-append when the title already has any trailing extension', async () => {
// Title says .pdf but caller asked for pptx — defensive: keep the
// user-visible title untouched rather than synthesising deck.pdf.pptx.
diff --git a/app/src/services/artifactDownloadService.ts b/app/src/services/artifactDownloadService.ts
index 078ad9fd04..c8d4681c2c 100644
--- a/app/src/services/artifactDownloadService.ts
+++ b/app/src/services/artifactDownloadService.ts
@@ -217,10 +217,11 @@ async function resolveArtifactForExport(
const title = resolved.meta?.title?.trim() || fallbackTitle.trim() || 'artifact';
const ext = extension.trim().replace(/^\.+/, '');
// Guard against double extensions: if `title` already ends in the
- // requested extension (case-insensitive, with any other extension also
- // tolerated), don't append again. Prevents `deck.pptx.pptx` when the
- // persisted title is `deck.pptx` and the caller passes `'pptx'`.
- const titleHasExtension = /\.[^./\\]+$/.test(title);
+ // requested extension (case-insensitive), or in another real one, don't
+ // append. Prevents `deck.pptx.pptx`, and keeps a title like `deck.pdf` as
+ // the user sees it. A real extension starts with a letter, so a title that
+ // only looks like it has one ("Release v1.2") still gets the extension.
+ const titleHasExtension = /\.[a-z][a-z0-9]{0,4}$/i.test(title);
const titleHasSameExt = ext.length > 0 && title.toLowerCase().endsWith(`.${ext.toLowerCase()}`);
const filename = ext && !titleHasExtension && !titleHasSameExt ? `${title}.${ext}` : title;