diff --git a/AGENTS.md b/AGENTS.md index ecb0cd7c..157601a0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,14 +2,14 @@ ## Commands -- `npm run dev` - Start both backend (5001) and frontend (5173) -- `npm run dev:backend` - Backend only: `bun --watch backend/src/index.ts` -- `npm run dev:frontend` - Frontend only: `cd frontend && vite` -- `npm run build` - Build both backend and frontend -- `npm run test` - Run backend tests: `cd backend && bun test` +- `pnpm dev` - Start both backend (5001) and frontend (5173) +- `pnpm dev:backend` - Backend only: `bun --watch backend/src/index.ts` +- `pnpm dev:frontend` - Frontend only: `cd frontend && vite` +- `pnpm build` - Build both backend and frontend +- `pnpm test` - Run backend tests: `cd backend && bun test` - `cd backend && bun test ` - Run single test file - `cd backend && vitest --ui` - Test UI with coverage -- `cd backend && vitest --coverage` - Coverage report +- `cd backend && vitest --coverage` - Coverage report (80% threshold) - `cd frontend && npm run lint` - Frontend linting ## Code Style @@ -20,16 +20,17 @@ ### Backend (Bun + Hono) -- Hono framework with Zod validation -- Error handling with try/catch and logging +- Hono framework with Zod validation, Better SQLite3 database +- Error handling with try/catch and structured logging - Follow existing route/service/utility structure - Use async/await consistently, avoid .then() chains +- Test coverage: 80% minimum required ### Frontend (React + Vite) - @/ alias for components: `import { Button } from '@/components/ui/button'` - Radix UI + Tailwind CSS, React Hook Form + Zod -- React Query for state management +- React Query (@tanstack/react-query) for state management - ESLint TypeScript rules enforced - Use React hooks properly, no direct state mutations @@ -37,5 +38,6 @@ - DRY principles, follow existing patterns - ./temp/opencode is reference only, never commit has opencode src -- Use shared types from workspace package +- Use shared types from workspace package (@opencode-manager/shared) - OpenCode server runs on port 5551, backend API on port 5001 +- Prefer pnpm over npm for all package management diff --git a/frontend/src/api/opencode.ts b/frontend/src/api/opencode.ts index 57ead674..844d9d33 100644 --- a/frontend/src/api/opencode.ts +++ b/frontend/src/api/opencode.ts @@ -127,6 +127,16 @@ export class OpenCodeClient { return response.data } + async revertMessage(sessionID: string, data: { messageID: string, partID?: string }) { + const response = await this.client.post(`/session/${sessionID}/revert`, data) + return response.data + } + + async unrevertSession(sessionID: string) { + const response = await this.client.post(`/session/${sessionID}/unrevert`) + return response.data + } + getEventSourceURL() { const base = this.baseURL.startsWith('http') ? this.baseURL diff --git a/frontend/src/components/message/EditableUserMessage.tsx b/frontend/src/components/message/EditableUserMessage.tsx new file mode 100644 index 00000000..d862d7fd --- /dev/null +++ b/frontend/src/components/message/EditableUserMessage.tsx @@ -0,0 +1,146 @@ +import { memo, useState, useRef, useEffect } from 'react' +import { Send, X, Pencil, Loader2 } from 'lucide-react' +import { useRefreshMessage } from '@/hooks/useRemoveMessage' + +interface EditableUserMessageProps { + opcodeUrl: string + sessionId: string + directory?: string + content: string + assistantMessageId: string + onCancel: () => void + model?: string + agent?: string +} + +export const EditableUserMessage = memo(function EditableUserMessage({ + opcodeUrl, + sessionId, + directory, + content, + assistantMessageId, + onCancel, + model, + agent +}: EditableUserMessageProps) { + const [editedContent, setEditedContent] = useState(content) + const textareaRef = useRef(null) + const refreshMessage = useRefreshMessage({ opcodeUrl, sessionId, directory }) + + useEffect(() => { + if (textareaRef.current) { + textareaRef.current.focus() + textareaRef.current.setSelectionRange( + textareaRef.current.value.length, + textareaRef.current.value.length + ) + } + }, []) + + useEffect(() => { + if (textareaRef.current) { + textareaRef.current.style.height = 'auto' + textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px` + } + }, [editedContent]) + + const handleSubmit = () => { + if (!editedContent.trim() || refreshMessage.isPending) return + + refreshMessage.mutate({ + assistantMessageID: assistantMessageId, + userMessageContent: editedContent.trim(), + model, + agent + }, { + onSuccess: () => { + onCancel() + } + }) + } + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) { + e.preventDefault() + handleSubmit() + } else if (e.key === 'Escape') { + e.preventDefault() + onCancel() + } + } + + return ( +
+