diff --git a/README.md b/README.md index 1874a138..1b4a21d4 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Shakespeare is an AI chat application that allows users to build custom Nostr we 1. **Create a Project**: Enter a description of what you want to build in the prompt textarea 2. **Chat with AI**: Use the AI assistant to add features, edit files, and build your website -3. **Attach Files**: Click the paperclip icon to attach files to your messages for AI analysis +3. **Attach Files**: Click the paperclip icon to attach files to your messages - they'll show as "Added file: /path/filename" 4. **Edit Code**: Switch to the code view to manually edit files if needed 5. **Preview**: View your website in the preview pane diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 81b1b093..8784cbca 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -306,7 +306,7 @@ export const ChatPane = forwardRef(({ const filePromises = attachedFiles.map(async (file) => { try { const savedPath = await saveFileToTmp(fs, file); - return `File added to ${savedPath}`; + return `Added file: ${savedPath}`; } catch (error) { console.error('Failed to save file:', error); return `Failed to save file: ${file.name}`; diff --git a/src/components/UserMessage.integration.test.tsx b/src/components/UserMessage.integration.test.tsx index 4c3dbd54..5665ee4e 100644 --- a/src/components/UserMessage.integration.test.tsx +++ b/src/components/UserMessage.integration.test.tsx @@ -7,42 +7,42 @@ describe('UserMessage Integration', () => { // Simulate the new text parts structure that ChatPane would create const content = [ { type: 'text' as const, text: 'Please analyze this file:' }, - { type: 'text' as const, text: 'File added to /tmp/data.csv' }, + { type: 'text' as const, text: 'Added file: /tmp/data.csv' }, { type: 'text' as const, text: 'Let me know what you find!' } ]; - + render(); - + // Check that regular text is displayed expect(screen.getByText('Please analyze this file:')).toBeInTheDocument(); expect(screen.getByText('Let me know what you find!')).toBeInTheDocument(); - + // Check that file attachment is rendered as a badge expect(screen.getByText('data.csv')).toBeInTheDocument(); - expect(screen.getByText('added to /tmp/data.csv')).toBeInTheDocument(); + expect(screen.getByText('/tmp/data.csv')).toBeInTheDocument(); }); it('handles single text part with file attachment', () => { const content = [ - { type: 'text' as const, text: 'File added to /tmp/script.js' } + { type: 'text' as const, text: 'Added file: /tmp/script.js' } ]; - + render(); - + expect(screen.getByText('script.js')).toBeInTheDocument(); - expect(screen.getByText('added to /tmp/script.js')).toBeInTheDocument(); + expect(screen.getByText('/tmp/script.js')).toBeInTheDocument(); }); it('handles multiple file attachments in separate parts', () => { const content = [ { type: 'text' as const, text: 'Here are my files:' }, - { type: 'text' as const, text: 'File added to /tmp/config.json' }, - { type: 'text' as const, text: 'File added to /tmp/styles.css' }, - { type: 'text' as const, text: 'File added to /tmp/main.js' } + { type: 'text' as const, text: 'Added file: /tmp/config.json' }, + { type: 'text' as const, text: 'Added file: /tmp/styles.css' }, + { type: 'text' as const, text: 'Added file: /tmp/main.js' } ]; - + render(); - + expect(screen.getByText('Here are my files:')).toBeInTheDocument(); expect(screen.getByText('config.json')).toBeInTheDocument(); expect(screen.getByText('styles.css')).toBeInTheDocument(); @@ -51,9 +51,9 @@ describe('UserMessage Integration', () => { it('handles empty content gracefully', () => { const content: Array<{ type: 'text'; text: string }> = []; - + const { container } = render(); - + expect(container.firstChild).toBeNull(); }); }); \ No newline at end of file diff --git a/src/components/UserMessage.test.tsx b/src/components/UserMessage.test.tsx index 440aa8d5..3b63e0a4 100644 --- a/src/components/UserMessage.test.tsx +++ b/src/components/UserMessage.test.tsx @@ -12,7 +12,7 @@ describe('UserMessage', () => { }); it('handles backward compatibility with string content containing file attachments', () => { - const content = 'Here is my file: File added to /tmp/test.txt'; + const content = 'Here is my file: Added file: /tmp/test.txt'; render(); @@ -23,21 +23,21 @@ describe('UserMessage', () => { it('renders file attachment badges for single file with text parts', () => { const content = [ { type: 'text' as const, text: 'Here is my file:' }, - { type: 'text' as const, text: 'File added to /tmp/test.txt' } + { type: 'text' as const, text: 'Added file: /tmp/test.txt' } ]; render(); expect(screen.getByText('Here is my file:')).toBeInTheDocument(); expect(screen.getByText('test.txt')).toBeInTheDocument(); - expect(screen.getByText('added to /tmp/test.txt')).toBeInTheDocument(); + expect(screen.getByText('/tmp/test.txt')).toBeInTheDocument(); }); it('renders multiple file attachments with text parts', () => { const content = [ { type: 'text' as const, text: 'Files uploaded:' }, - { type: 'text' as const, text: 'File added to /tmp/document.pdf' }, - { type: 'text' as const, text: 'File added to /tmp/image.jpg' }, + { type: 'text' as const, text: 'Added file: /tmp/document.pdf' }, + { type: 'text' as const, text: 'Added file: /tmp/image.jpg' }, { type: 'text' as const, text: 'All done!' } ]; @@ -50,7 +50,7 @@ describe('UserMessage', () => { }); it('renders text files with FileText icon', () => { - const content = [{ type: 'text' as const, text: 'File added to /tmp/script.js' }]; + const content = [{ type: 'text' as const, text: 'Added file: /tmp/script.js' }]; render(); @@ -59,27 +59,27 @@ describe('UserMessage', () => { }); it('handles files without extensions', () => { - const content = [{ type: 'text' as const, text: 'File added to /tmp/README' }]; + const content = [{ type: 'text' as const, text: 'Added file: /tmp/README' }]; render(); expect(screen.getByText('README')).toBeInTheDocument(); - expect(screen.getByText('added to /tmp/README')).toBeInTheDocument(); + expect(screen.getByText('/tmp/README')).toBeInTheDocument(); }); it('handles complex filenames with underscores and numbers', () => { - const content = [{ type: 'text' as const, text: 'File added to /tmp/my_file_1.txt' }]; + const content = [{ type: 'text' as const, text: 'Added file: /tmp/my_file_1.txt' }]; render(); expect(screen.getByText('my_file_1.txt')).toBeInTheDocument(); - expect(screen.getByText('added to /tmp/my_file_1.txt')).toBeInTheDocument(); + expect(screen.getByText('/tmp/my_file_1.txt')).toBeInTheDocument(); }); it('preserves whitespace in text content', () => { const content = [ { type: 'text' as const, text: 'Line 1\n\nLine 3 with spaces \n\nFinal line' }, - { type: 'text' as const, text: 'File added to /tmp/test.txt' } + { type: 'text' as const, text: 'Added file: /tmp/test.txt' } ]; const { container } = render(); @@ -94,7 +94,7 @@ describe('UserMessage', () => { it('handles mixed content with file attachments in the middle', () => { const content = [ { type: 'text' as const, text: 'Starting text' }, - { type: 'text' as const, text: 'File added to /tmp/middle.txt' }, + { type: 'text' as const, text: 'Added file: /tmp/middle.txt' }, { type: 'text' as const, text: 'ending text' } ]; diff --git a/src/components/UserMessage.tsx b/src/components/UserMessage.tsx index 8e219de4..533a9697 100644 --- a/src/components/UserMessage.tsx +++ b/src/components/UserMessage.tsx @@ -9,7 +9,7 @@ interface UserMessageProps { /** * Component to render user messages nicely * Handles both string content and array content (text parts) - * Detects "File added to /tmp/" patterns and renders them as badges + * Detects "Added file: /tmp/" patterns and renders them as badges */ export function UserMessage({ content }: UserMessageProps) { // Convert content to array format for uniform processing @@ -17,8 +17,8 @@ export function UserMessage({ content }: UserMessageProps) { ? [{ type: 'text' as const, text: content }] : content.filter(part => part.type === 'text') as Array<{ type: 'text'; text: string }>; - // Regular expression to match "File added to /tmp/" patterns - const filePattern = /^File added to (\/tmp\/[^\s\n]+)$/; + // Regular expression to match "Added file: /tmp/" patterns + const filePattern = /^Added file: (\/tmp\/[^\s\n]+)$/; // Process each content part and categorize as text or file const processedParts: Array<{ type: 'text' | 'file'; content: string; filepath?: string }> = []; @@ -75,7 +75,7 @@ export function UserMessage({ content }: UserMessageProps) { {getFileIcon(filename)} {filename} - added to {part.filepath} + {part.filepath} );