2025-12-24 13:06:09 +01:00
# AGENTS.md
2026-02-23 20:39:58 +08:00
## Purpose
This file defines the always-on rules for AI agents working on 5chan.
Use this as the default policy. Load linked playbooks only when their trigger condition applies.
2026-02-24 14:01:18 +08:00
## Surprise Handling
The role of this file is to reduce recurring agent mistakes and confusion points in this repository.
If you encounter something surprising or ambiguous while working, alert the developer immediately.
After confirmation, add a concise entry to `docs/agent-playbooks/known-surprises.md` so future agents avoid the same issue.
Only record items that are repo-specific, likely to recur, and have a concrete mitigation.
2025-12-24 13:06:09 +01:00
## Project Overview
2026-02-27 13:56:29 +08:00
5chan is a serverless, adminless, decentralized imageboard built on the Bitsocial protocol.
2025-12-24 13:06:09 +01:00
2026-02-23 20:39:58 +08:00
## Instruction Priority
- **MUST** rules are mandatory.
- **SHOULD** rules are strong defaults unless task context requires a different choice.
- If guidance conflicts, prefer: user request > MUST > SHOULD > playbooks.
## Task Router (Read First)
| Situation | Required action |
|---|---|
| React UI logic changed (`src/components` , `src/views` , `src/hooks` , UI stores) | Follow React architecture rules below and run `yarn doctor` |
| `package.json` changed | Run `yarn install` to keep `yarn.lock` in sync |
2026-03-07 21:31:20 +08:00
| Dependencies or import graph changed | Run `yarn knip` as an advisory manifest/import audit |
2026-02-23 21:14:55 +08:00
| Translation key/value changed | Use `docs/agent-playbooks/translations.md` |
| Bug report in a specific file/line | Start with git history scan from `docs/agent-playbooks/bug-investigation.md` before editing |
2026-02-23 20:39:58 +08:00
| `CHANGELOG.md` or package version changed | Run `yarn blotter:check` ; if needed add a concise release one-liner |
| UI/visual behavior changed | Verify in browser with `playwright-cli` ; test desktop and mobile viewport |
| GitHub operation needed | Use `gh` CLI, not GitHub MCP |
2026-02-23 21:14:55 +08:00
| User asks for commit/issue phrasing | Use `docs/agent-playbooks/commit-issue-format.md` |
2026-02-24 14:01:18 +08:00
| Surprising/ambiguous repo behavior encountered | Alert developer and, once confirmed, document in `docs/agent-playbooks/known-surprises.md` |
2026-02-23 20:39:58 +08:00
2025-12-24 13:06:09 +01:00
## Stack
2026-02-23 20:39:58 +08:00
- React 19 + TypeScript
- Zustand for shared state
- React Router v6
- Vite
2026-03-05 17:14:23 +08:00
- bitsocial-react-hooks
2026-02-23 20:39:58 +08:00
- i18next
- yarn
- oxlint
- oxfmt
- tsgo
2025-12-24 13:06:09 +01:00
## Project Structure
2026-02-23 20:39:58 +08:00
```text
2025-12-24 13:06:09 +01:00
src/
2026-02-23 20:39:58 +08:00
├── components/ # Reusable UI components
├── views/ # Page-level route views
├── hooks/ # Custom hooks
├── stores/ # Zustand stores
├── lib/ # Utilities/helpers
└── data/ # Static data
2025-12-24 13:06:09 +01:00
```
2026-02-23 20:39:58 +08:00
## Core MUST Rules
2025-12-24 13:06:09 +01:00
2026-02-23 20:39:58 +08:00
### Package and Dependency Rules
2025-12-24 13:06:09 +01:00
2026-02-23 20:39:58 +08:00
- Use `yarn` , never `npm` .
- Pin exact dependency versions (`package@x.y.z` ), never `^` or `~` .
- Keep lockfile synchronized when dependency manifests change.
2026-01-27 13:18:31 +08:00
2026-02-23 20:39:58 +08:00
### React Architecture Rules
- Do not use `useState` for shared/global state. Use Zustand stores in `src/stores/` .
2026-03-05 17:14:23 +08:00
- Do not use `useEffect` for data fetching. Use `bitsocial-react-hooks` .
2026-02-23 20:39:58 +08:00
- Do not sync derived state with effects. Compute during render.
- Avoid copy-paste logic across components. Extract custom hooks in `src/hooks/` .
- Avoid boolean flag soup for complex flows; model state clearly in Zustand.
- Use React Router for navigation; no manual history manipulation.
### Code Organization Rules
- Keep components focused; split large components.
- Follow DRY: shared UI in `src/components/` , shared logic in `src/hooks/` .
- Add comments for complex/non-obvious code; skip obvious comments.
### Bug Investigation Rules
- For bug reports tied to a specific file/line, check relevant git history before any fix.
- Minimum sequence: `git log --oneline` or `git blame` first, then scoped `git show` for relevant commits.
2026-02-23 21:14:55 +08:00
- Full workflow: `docs/agent-playbooks/bug-investigation.md` .
2026-02-23 20:39:58 +08:00
### Verification Rules
- Never mark work complete without verification.
- After code changes, run: `yarn build` , `yarn lint` , `yarn type-check` .
2026-03-07 21:31:20 +08:00
- After adding or changing tests, run `yarn test` .
2026-03-09 18:53:25 +08:00
- Do not commit or force-add local rebuild output. `build/` is the main generated build output in this repo; remove or restore generated output directories after local verification before committing.
2026-02-23 20:39:58 +08:00
- After React UI logic changes, run: `yarn doctor` .
- Treat React Doctor output as actionable guidance; prioritize `error` then `warning` .
- For UI/visual changes, verify with `playwright-cli` on desktop and mobile viewport.
2026-03-07 21:31:20 +08:00
- Use `yarn test:coverage` as an advisory check when expanding test coverage or auditing risky logic; do not invent a repo-wide coverage gate unless the user asks for one.
2026-02-23 20:39:58 +08:00
- If verification fails, fix and re-run until passing.
### Tooling Constraints
- Use `gh` CLI for GitHub work (issues, PRs, actions, dependabot, projects, search).
- Do not use GitHub MCP.
- Do not use browser MCP servers (cursor-ide-browser, playwright-mcp, chrome MCP, etc.).
- Use `playwright-cli` for browser automation.
- If many MCP tools are present in context, warn user and suggest disabling unused MCPs.
### Project Maintenance Rules
- If `CHANGELOG.md` or package version changes, run `yarn blotter:check` .
- If blotter check fails for missing release coverage, add a concise one-line release entry.
- Ignore manual entries for release coverage logic.
- Use `yarn blotter` / `yarn blotter:manual` for manual dev messages.
### Security and Boundaries
- Never commit secrets or API keys.
2026-02-26 13:25:35 +08:00
- Never push to a remote unless the user explicitly asks.
2026-02-23 20:39:58 +08:00
- Test responsive behavior on mobile viewport.
## Core SHOULD Rules
- Keep context lean: delegate heavy/verbose tasks to subprocesses when available.
- For complex work, parallelize independent checks.
2026-03-07 21:31:20 +08:00
- Add or update tests for bug fixes and non-trivial logic changes when the code is reasonably testable.
2026-03-08 13:10:25 +08:00
- When touching already-covered code, prefer extending nearby tests so measured coverage does not regress without a clear reason.
2026-03-07 21:31:20 +08:00
- Use `yarn knip` when adding/removing dependencies or introducing new direct imports; treat findings as advisory, but resolve real issues before finishing.
2026-02-23 20:39:58 +08:00
- When proposing or implementing meaningful code changes, include both:
- a Conventional Commit title suggestion
- a short GitHub issue suggestion
2026-02-23 21:14:55 +08:00
Use the format playbook: `docs/agent-playbooks/commit-issue-format.md` .
2026-02-23 20:39:58 +08:00
- When stuck on a bug, search the web for recent fixes/workarounds.
- After user corrections, identify root cause and apply the lesson in subsequent steps.
2026-02-24 14:29:31 +08:00
## Local Development URLs
This project uses [Portless ](https://github.com/vercel-labs/portless ) for local dev. The dev server is available at http://5chan.localhost:1355 instead of a random port. Other Bitsocial projects use the same proxy (seedit, mintpass, bitsocial at `.localhost:1355` ), so they can all run simultaneously without port conflicts.
To bypass Portless: `PORTLESS=0 yarn start`
2026-02-23 20:39:58 +08:00
## Common Commands
2026-01-27 13:18:31 +08:00
```bash
2026-02-23 20:39:58 +08:00
yarn install
2026-02-24 14:29:31 +08:00
yarn start # http://5chan.localhost:1355
2026-02-23 20:39:58 +08:00
yarn build
yarn test
2026-03-07 21:31:20 +08:00
yarn test:coverage
yarn knip
yarn knip:full
2026-02-23 20:39:58 +08:00
yarn prettier
yarn electron
yarn doctor
yarn doctor:score
yarn doctor:verbose
2026-01-27 13:18:31 +08:00
```
2026-02-23 20:39:58 +08:00
## Playbooks (Load On Demand)
2026-01-27 13:18:31 +08:00
2026-02-23 20:39:58 +08:00
Use these only when relevant to the active task:
2026-01-27 13:18:31 +08:00
2026-02-23 21:14:55 +08:00
- Hooks setup and scripts: `docs/agent-playbooks/hooks-setup.md`
- Translations workflow: `docs/agent-playbooks/translations.md`
- Commit/issue output format: `docs/agent-playbooks/commit-issue-format.md`
- Skills/tools setup and MCP rationale: `docs/agent-playbooks/skills-and-tools.md`
- Bug investigation workflow: `docs/agent-playbooks/bug-investigation.md`
2026-02-24 14:01:18 +08:00
- Known surprises log: `docs/agent-playbooks/known-surprises.md`