diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..748fe7e6 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,105 @@ +# AGENTS.md + +## Project Overview + +5chan is a serverless, adminless, decentralized 4chan alternative built on the Plebbit protocol. + +## Stack + +- **React 19** with TypeScript +- **Zustand** for state management +- **React Router v6** for routing +- **Vite** for bundling +- **plebbit-react-hooks** for Plebbit protocol integration +- **i18next** for translations +- **yarn** as package manager + +## Commands + +```bash +yarn install # Install dependencies +yarn start # Start dev server (port 3000) +yarn build # Production build +yarn test # Run tests +yarn prettier # Format code +yarn electron # Run Electron app +``` + +## Code Style + +- TypeScript strict mode +- Prettier for formatting (runs on pre-commit) +- Follow DRY principle—extract reusable components + +## React Patterns (Critical) + +AI tends to overuse `useState` and `useEffect`. This project follows modern React patterns instead. + +### Do NOT + +- Use `useState` for shared/global state → use **Zustand stores** in `src/stores/` +- Use `useEffect` for data fetching → use **plebbit-react-hooks** (already handles caching, loading states) +- Copy-paste logic across components → extract into **custom hooks** in `src/hooks/` +- Use boolean flag soup (`isLoading`, `isError`, `isSuccess`) → use **state machines** with Zustand +- Use `useEffect` to sync derived state → **calculate during render** instead + +### Do + +- Use Zustand for any state shared between components +- Use plebbit-react-hooks (`useComment`, `useFeed`, `useSubplebbit`, etc.) for all Plebbit data +- Extract reusable logic into custom hooks +- Calculate derived values during render, not in effects +- Use `useMemo` only when profiling shows it's needed +- Use React Router for navigation (no manual history manipulation) + +### Quick Reference + +| Concern | ❌ Avoid | ✅ Use Instead | +|---------|----------|----------------| +| Shared state | `useState` + prop drilling | Zustand store | +| Data fetching | `useEffect` + fetch | plebbit-react-hooks | +| Derived state | `useEffect` to sync | Calculate during render | +| Side effects | Effects without cleanup | AbortController or query libs | +| Complex flows | Boolean flags | State machine in Zustand | +| Logic reuse | Copy-paste | Custom hooks | + +## Project Structure + +``` +src/ +├── components/ # Reusable UI components +├── views/ # Page-level components (routes) +├── hooks/ # Custom React hooks +├── stores/ # Zustand stores +├── lib/ # Utilities and helpers +└── data/ # Static data (default subplebbits, etc.) +``` + +## Documentation + +The following docs exist for deeper guidance. **Do not read them automatically**—they are large and will bloat the context window. Instead: +- Be aware they exist +- Consult them when relevant to the task or when the user asks +- Offer to read them if the user seems to need React pattern guidance + +Available docs: +- **[docs/react-guide.md](docs/react-guide.md)** — Bad vs good React patterns with code examples +- **[docs/you-might-not-need-an-effect.md](docs/you-might-not-need-an-effect.md)** — When to avoid useEffect (comprehensive) + +## Context Window Warning + +MCP servers can silently bloat the context window with tool definitions, even when unused. If you notice: +- Responses getting cut off or degraded +- The agent "forgetting" earlier conversation context +- Unusually slow responses + +**Tell the user**: "You may have too many MCP servers enabled. Consider disabling unused ones to free up context window space." The user may not be aware this is happening—MCP tool definitions consume tokens even if you never call them. + +## Boundaries + +- Never commit secrets or API keys +- Use yarn, not npm +- Keep components focused—split large components +- Add comments for complex logic, skip obvious code +- Test on mobile viewport (this is a responsive app) +