diff --git a/README.md b/README.md index aadda3b1..8ffaf5a1 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ a wall others can remix, with attribution back to the original. ## Quick start -Node.js >= 18 and pnpm. Nothing else — no database to install, no tmux. +Node.js >= 22 and pnpm. Nothing else — no database to install, no tmux. ```bash git clone https://github.com/CodeFox-Repo/codefox.git diff --git a/frontend/jest.onboarding-copy.config.js b/frontend/jest.onboarding-copy.config.js new file mode 100644 index 00000000..e5a1b8db --- /dev/null +++ b/frontend/jest.onboarding-copy.config.js @@ -0,0 +1,15 @@ +module.exports = { + rootDir: '.', + testEnvironment: 'jsdom', + testMatch: ['/src/**/__tests__/onboarding-copy.test.tsx'], + moduleNameMapper: { '^@/(.*)$': '/src/$1' }, + transform: { + '^.+\\.tsx?$': [ + 'ts-jest', + { + tsconfig: { jsx: 'react-jsx', module: 'commonjs' }, + diagnostics: false, + }, + ], + }, +}; diff --git a/frontend/src/components/auth-choice-modal.tsx b/frontend/src/components/auth-choice-modal.tsx index 5b2631e4..2bf9ffca 100644 --- a/frontend/src/components/auth-choice-modal.tsx +++ b/frontend/src/components/auth-choice-modal.tsx @@ -23,7 +23,7 @@ export function AuthChoiceModal({ {/* Invisible but accessible DialogTitle */} - Choose Authentication Method + Welcome to CodeFox @@ -32,7 +32,7 @@ export function AuthChoiceModal({ Welcome to CodeFox

- Choose how you want to continue + Sign in or create an account to continue

{/* Sign In button */} diff --git a/frontend/src/components/chat/chat-bottombar.tsx b/frontend/src/components/chat/chat-bottombar.tsx index 00a0ce2b..28f76d12 100644 --- a/frontend/src/components/chat/chat-bottombar.tsx +++ b/frontend/src/components/chat/chat-bottombar.tsx @@ -27,8 +27,8 @@ import { * entry fall back to the raw tag so a config change still renders. */ const MODEL_LABELS: Record = { - 'google/gemini-3.7-flash@openrouter': '快速 · Fast', - 'accounts/fireworks/models/qwen3p8-max': '强力 · Max', + 'google/gemini-3.7-flash@openrouter': 'Fast', + 'accounts/fireworks/models/qwen3p8-max': 'Max', }; const modelLabel = (id: string) => MODEL_LABELS[id] ?? id; @@ -366,9 +366,10 @@ export default function ChatBottombar({ onFocus={() => setIsFocused(true)} onBlur={() => setIsFocused(false)} name="message" + aria-label="Message CodeFox" placeholder={ isStreaming - ? 'Keep typing — sends when the agent finishes this turn' + ? 'Write your next message. Press Enter or select Send to queue it.' : 'Describe a change — the agent edits the real files' } className="resize-none px-2 py-2.5 w-full focus:outline-none bg-transparent text-foreground text-sm placeholder:text-muted-foreground dark:placeholder:text-muted-foreground" @@ -387,7 +388,7 @@ export default function ChatBottombar({ type="button" onClick={queueCurrentInput} className="flex h-7 w-7 items-center justify-center rounded-md bg-secondary text-foreground transition-colors hover:bg-accent" - aria-label="Queue for the next turn" + aria-label="Send: queue message for the next turn" > diff --git a/frontend/src/components/chat/question-card.tsx b/frontend/src/components/chat/question-card.tsx index cd3357f7..48d345bc 100644 --- a/frontend/src/components/chat/question-card.tsx +++ b/frontend/src/components/chat/question-card.tsx @@ -250,7 +250,7 @@ export function QuestionCard({ {q.label} {q.multi && ( - multi + Select all that apply )}

@@ -322,6 +322,7 @@ export function QuestionCard({ {interactive && (
setNote(e.target.value)} placeholder="Anything else the agent should know? (optional)" diff --git a/frontend/src/components/root/__tests__/onboarding-copy.test.tsx b/frontend/src/components/root/__tests__/onboarding-copy.test.tsx new file mode 100644 index 00000000..7930a6d9 --- /dev/null +++ b/frontend/src/components/root/__tests__/onboarding-copy.test.tsx @@ -0,0 +1,189 @@ +import React, { createRef } from 'react'; +import { act, fireEvent, render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { PromptForm } from '../prompt-form'; +import ChatBottombar from '../../chat/chat-bottombar'; + +let mockMutationOptions: { + onCompleted: (data: unknown) => void; + onError: (error: Error) => void; +}; +const mockRegenerate = jest.fn(); +jest.mock('@apollo/client', () => ({ + gql: () => 'query', + useQuery: () => ({ data: undefined }), + useMutation: (_query: unknown, options: typeof mockMutationOptions) => { + mockMutationOptions = options; + return [mockRegenerate]; + }, +})); +jest.mock('@/hooks/useModels', () => ({ + useModels: () => ({ + models: [], + loading: false, + setSelectedModel: jest.fn(), + }), +})); +jest.mock('@/app/log/logger', () => ({ logger: { error: jest.fn() } })); +jest.mock('typewriter-effect', () => () => null); +jest.mock('next/image', () => ({ + __esModule: true, + default: (props: React.ImgHTMLAttributes) => ( + + ), +})); +jest.mock('framer-motion', () => ({ + motion: { + div: ({ children, initial, animate, exit, transition, ...props }: any) => ( +
{children}
+ ), + }, + AnimatePresence: ({ children }: { children: React.ReactNode }) => ( + <>{children} + ), +})); + +beforeEach(() => jest.clearAllMocks()); + +function prompt(authorized = true) { + const onSubmit = jest.fn(); + const onAuthRequired = jest.fn(); + render( + + ); + const input = screen.getByRole('textbox', { name: 'Describe your project' }); + return { input, onSubmit, onAuthRequired }; +} + +test('empty creation explains what is needed without opening sign-in', () => { + const { input, onSubmit, onAuthRequired } = prompt(false); + fireEvent.click(screen.getByRole('button', { name: 'Create project' })); + expect(screen.getByRole('alert')).toHaveTextContent( + 'Describe your project first.' + ); + expect(input).toHaveAttribute('aria-invalid', 'true'); + expect(onSubmit).not.toHaveBeenCalled(); + expect(onAuthRequired).not.toHaveBeenCalled(); + fireEvent.change(input, { target: { value: 'A portfolio' } }); + expect(screen.queryByRole('alert')).toBeNull(); +}); + +test('empty improvement explains the prerequisite and makes no request', () => { + prompt(); + fireEvent.click(screen.getByRole('button', { name: 'Improve prompt' })); + expect(screen.getByRole('alert')).toHaveTextContent( + 'Describe your project first.' + ); + expect(mockRegenerate).not.toHaveBeenCalled(); +}); + +test('sign-in interruption keeps the entered prompt without starting generation', () => { + const { input, onAuthRequired, onSubmit } = prompt(false); + fireEvent.change(input, { + target: { value: 'A portfolio for an architect' }, + }); + fireEvent.click(screen.getByRole('button', { name: 'Create project' })); + expect(onAuthRequired).toHaveBeenCalledTimes(1); + expect(onSubmit).not.toHaveBeenCalled(); + expect(input).toHaveValue('A portfolio for an architect'); +}); + +test('improvement reports pending until the mutation succeeds and blocks repeated clicks', () => { + const { input } = prompt(); + fireEvent.change(input, { target: { value: 'A portfolio' } }); + fireEvent.click(screen.getByRole('button', { name: 'Improve prompt' })); + const pending = screen.getByRole('button', { name: 'Improving prompt…' }); + expect(pending).toBeDisabled(); + expect(input).toBeDisabled(); + fireEvent.click(pending); + expect(mockRegenerate).toHaveBeenCalledTimes(1); + act(() => + mockMutationOptions.onCompleted({ + regenerateDescription: 'A portfolio with selected projects', + }) + ); + expect(input).toHaveValue('A portfolio with selected projects'); + expect(screen.getByRole('button', { name: 'Prompt improved' })).toBeEnabled(); + fireEvent.change(input, { target: { value: 'A changed brief' } }); + expect(screen.getByRole('button', { name: 'Improve prompt' })).toBeEnabled(); +}); + +test('failed improvement preserves text and exposes a retryable error', () => { + const { input } = prompt(); + fireEvent.change(input, { target: { value: 'A portfolio' } }); + fireEvent.click(screen.getByRole('button', { name: 'Improve prompt' })); + act(() => mockMutationOptions.onError(new Error('Network unavailable'))); + expect(input).toHaveValue('A portfolio'); + expect(input).toBeEnabled(); + expect(screen.getByRole('alert')).toHaveTextContent( + "Couldn't improve your prompt. Your text is still here. Try again." + ); + fireEvent.click(screen.getByRole('button', { name: 'Improve prompt' })); + expect(mockRegenerate).toHaveBeenCalledTimes(2); + expect(screen.queryByRole('alert')).toBeNull(); +}); + +test('an empty mutation result never replaces the draft or reports success', () => { + const { input } = prompt(); + fireEvent.change(input, { target: { value: 'A portfolio' } }); + fireEvent.click(screen.getByRole('button', { name: 'Improve prompt' })); + act(() => mockMutationOptions.onCompleted({ regenerateDescription: '' })); + expect(input).toHaveValue('A portfolio'); + expect(screen.getByRole('alert')).toBeInTheDocument(); + expect(screen.queryByRole('button', { name: 'Prompt improved' })).toBeNull(); +}); + +function chat() { + const onQueue = jest.fn(); + const setInput = jest.fn(); + const submit = jest.fn(); + render( + ()} + setInput={setInput} + setMessages={jest.fn()} + isStreaming + onQueue={onQueue} + /> + ); + return { + onQueue, + setInput, + submit, + input: screen.getByRole('textbox', { name: 'Message CodeFox' }), + }; +} + +test('writing alone does not queue; Enter queues and clears the input', () => { + const { onQueue, setInput, submit, input } = chat(); + expect(input).toHaveAttribute( + 'placeholder', + 'Write your next message. Press Enter or select Send to queue it.' + ); + expect(onQueue).not.toHaveBeenCalled(); + fireEvent.keyDown(input, { key: 'Enter', shiftKey: true }); + expect(onQueue).not.toHaveBeenCalled(); + fireEvent.keyDown(input, { key: 'Enter' }); + expect(onQueue).toHaveBeenCalledWith('Make it green'); + expect(setInput).toHaveBeenCalledWith(''); + expect(submit).not.toHaveBeenCalled(); +}); + +test('the Send control explicitly queues the next message', () => { + const { onQueue } = chat(); + fireEvent.click( + screen.getByRole('button', { + name: 'Send: queue message for the next turn', + }) + ); + expect(onQueue).toHaveBeenCalledTimes(1); +}); diff --git a/frontend/src/components/root/landing.tsx b/frontend/src/components/root/landing.tsx index edc4c7b6..73b8b1d3 100644 --- a/frontend/src/components/root/landing.tsx +++ b/frontend/src/components/root/landing.tsx @@ -33,20 +33,20 @@ const TOOL_CALLS = [ const FACTS = [ { - n: '365', - title: 'files in the app starter', - hint: 'Next.js 15 + shadcn — or a one-file HTML page, your pick', + n: '2', + title: 'starter types', + hint: 'A self-contained HTML page or a Next.js app', accent: true, }, { - n: '1', - title: 'dependency install, ever', - hint: '629 packages cached once, shared by every project', + n: 'Live', + title: 'preview beside the chat', + hint: 'Review the page as you build and refine it', }, { - n: '0', - title: 'cloud keys required', - hint: 'Any OpenAI- or Anthropic-compatible endpoint works', + n: 'Your choice', + title: 'model provider', + hint: 'Self-hosting requires a configured model provider', }, ]; @@ -54,12 +54,12 @@ const LIMITS = [ { title: 'The sandbox is not isolation', tag: 'by design', - body: 'The agent runs with the backend process privileges inside a scoped directory. That is the trade for using the CLI you are already signed into. Swap in a network sandbox provider for anything untrusted — same interface.', + body: 'The agent runs with the backend process privileges inside a scoped directory. Swap in a network sandbox provider for anything untrusted — same interface.', }, { title: 'Projects share one node_modules', tag: 'known', - body: 'Every project comes from the same template, so they symlink a single install. That stops being true the moment the agent is allowed to add a dependency.', + body: 'Next.js projects share the starter dependency install. That stops being true the moment the agent is allowed to add a dependency.', }, { title: 'Two starters, not a marketplace', @@ -153,21 +153,20 @@ export function Landing() { transition={{ duration: 0.5, ease: [0.16, 1, 0.3, 1] }} >
- Local-first - Claude Code inside + Self-hostable + AI-assisted MIT

- One prompt. -
A repo that{' '} - already runs. + Describe a page. +
+ Build it.

- CodeFox scaffolds a real Next.js project on your disk, points - Claude Code at it, and boots a dev server beside the chat. Not a - preview of code — the code, on a port, in your browser. + CodeFox creates a webpage or Next.js app from your prompt. Preview + the result beside the chat, then describe what to change.

@@ -216,7 +215,7 @@ export function Landing() {

- Node 18+ · no database to install · no cloud API key + Self-host with Node 22+ and a configured model provider

@@ -393,11 +392,11 @@ export function Landing() {

- Clone it, run one command, type one sentence. + Run CodeFox on your own machine.

- All of it happens on your machine. If it does not work in the - first minute, that is a bug worth filing. + Clone the repository, install the dependencies, and configure a + model provider. The setup guide walks you through each step.

@@ -419,7 +418,7 @@ export function Landing() { )}

- MIT · Node 18+ · macOS, Linux, WSL + MIT · Node 22+ · macOS, Linux, WSL

diff --git a/frontend/src/components/root/prompt-form.tsx b/frontend/src/components/root/prompt-form.tsx index 904beb4c..d970ae95 100644 --- a/frontend/src/components/root/prompt-form.tsx +++ b/frontend/src/components/root/prompt-form.tsx @@ -1,6 +1,12 @@ 'use client'; -import { useState, forwardRef, useImperativeHandle, useEffect } from 'react'; +import { + useState, + forwardRef, + useImperativeHandle, + useEffect, + useId, +} from 'react'; import { SendIcon, Sparkles, Globe, Lock, Loader2, Cpu } from 'lucide-react'; import Typewriter from 'typewriter-effect'; import { @@ -67,6 +73,9 @@ export const PromptForm = forwardRef( ref ) { const [message, setMessage] = useState(''); + const [promptError, setPromptError] = useState(''); + const promptId = useId(); + const errorId = `${promptId}-error`; // Light by default: a page, not a toolchain. The full Next starter is // the plug-in choice for when a real app is the goal. const [scenarioId, setScenarioId] = useState('landing'); @@ -106,7 +115,16 @@ export const PromptForm = forwardRef( REGENERATE_DESCRIPTION, { onCompleted: (data) => { + if (!data?.regenerateDescription?.trim()) { + setPromptError( + "Couldn't improve your prompt. Your text is still here. Try again." + ); + setIsEnhanced(false); + setIsRegenerating(false); + return; + } setMessage(data.regenerateDescription); + setPromptError(''); // Only now is the prompt actually enhanced. The button used to flip // to "Enhanced" on click, including on an empty box or a failure. setIsEnhanced(true); @@ -114,6 +132,9 @@ export const PromptForm = forwardRef( }, onError: (error) => { logger.error('Error regenerating description:', error); + setPromptError( + "Couldn't improve your prompt. Your text is still here. Try again." + ); setIsEnhanced(false); setIsRegenerating(false); }, @@ -122,6 +143,11 @@ export const PromptForm = forwardRef( const handleSubmit = () => { if (isLoading || isRegenerating) return; + if (!message.trim()) { + setPromptError('Describe your project first.'); + return; + } + setPromptError(''); if (!isAuthorized) { onAuthRequired(); } else { @@ -131,6 +157,11 @@ export const PromptForm = forwardRef( const handleMagicEnhance = () => { if (isLoading || isRegenerating) return; + if (!message.trim()) { + setPromptError('Describe your project first.'); + return; + } + setPromptError(''); if (!isAuthorized) { onAuthRequired(); return; @@ -166,10 +197,12 @@ export const PromptForm = forwardRef( }), clearMessage: () => { setMessage(''); + setPromptError(''); setIsEnhanced(false); }, setMessage: (text: string) => { setMessage(text); + setPromptError(''); setIsEnhanced(false); }, })); @@ -185,12 +218,23 @@ export const PromptForm = forwardRef( return (
+ {/* Typewriter */}