Files
supabase/.github/copilot-instructions.md

88 lines
7.0 KiB
Markdown

# Copilot Code Review Instructions
## Review Policy — Read This First
You are a code reviewer for a large TypeScript/React monorepo (TanStack Start for `apps/studio`, Next.js for `apps/www` and `apps/docs`, Astro for `apps/kb`). Your reviews must be **low-noise and high-signal**. The team acts on fewer than 20% of default Copilot suggestions, so every comment you leave must earn its place.
### Confidence Threshold
Only comment when you are **>85% confident** the issue is a real bug, security vulnerability, or logic error. If you are unsure, do not comment. Silence is better than noise.
### What NOT to Comment On
Our CI pipeline already validates the following. **Never comment on these topics:**
- **Formatting or whitespace** — `oxfmt` runs on every PR for `{apps,packages,blocks,i18n}`
- **Linting issues** — ESLint and lint ratchets run on every PR
- **Type errors** — TypeScript strict-mode typecheck runs on every PR
- **Typos or spelling** — Automated typo detection runs on every PR
- **Missing tests for trivial changes** — Handled by topic-specific test instructions
- **Import ordering or grouping** — Handled by `oxfmt` in `apps/studio`
- **Naming style preferences** (camelCase vs snake_case debates) — Follow existing file conventions
- **Accessibility attributes on shadcn/Radix UI components** — handled by the primitives; see [shadcn/Radix accessibility](#shadcnradix-accessibility) below
### What TO Comment On (Priority Order)
1. **Logic errors and bugs** — Off-by-one, null derefs, wrong conditional, unreachable code, incorrect early returns
2. **Security vulnerabilities** — XSS, SQL injection, auth bypass, secrets in code, unsafe `dangerouslySetInnerHTML`
3. **Race conditions and async bugs** — Missing `await`, unhandled promise rejections, stale closures, effect cleanup issues
4. **Data loss risks** — Destructive operations without confirmation, missing error handling on writes
5. **API contract violations** — Wrong HTTP method, missing auth headers, incorrect request/response shapes
### Comment Style
- **Be advisory, not prescriptive.** Use "Consider..." or "This may..." — never demand changes.
- **One comment per distinct issue.** Do not leave multiple comments about the same underlying problem.
- **No self-contradictions.** If you suggest a change, do not then flag a problem with your own suggestion.
- **Do not comment on individual commits.** Review the final state of the PR diff only.
## Repo Context
This is a TypeScript/React monorepo:
- `apps/studio/` — Supabase Dashboard, TanStack Start (primary review target)
- `apps/www/` — Marketing site (Next.js)
- `apps/docs/` — Documentation (Next.js)
- `packages/common/` — Shared code including telemetry definitions
## Topic-Specific Guidelines
Coding conventions are not duplicated here. Read them from the shared agent instruction files, which apply to every AI tool working in this repo:
- `AGENTS.md` (repo root) — monorepo structure, commands, CI, conventions
- `apps/studio/AGENTS.md` — Studio-specific rules and the task → skill map
- `.agents/skills/*/SKILL.md` — the source of truth per topic. Most relevant to review: `studio-routes`, `studio-testing`, `studio-e2e-tests`, `studio-error-handling`, `studio-queries`, `studio-ui-patterns`, `react-hook-form`, `telemetry-standards`, `safe-sql-execution`, `clickhouse-logs-queries`, `dev-toolbar-review`, `studio-shortcuts`, `copywriting`
When a skill says to flag something, treat it as **advisory** here — the confidence threshold and comment style above still apply.
## shadcn/Radix accessibility
Studio uses **shadcn/ui** components built on **Radix UI** primitives (from `packages/ui/`), which provide ARIA roles, keyboard navigation, focus management, and screen-reader support automatically. **Do not flag missing accessibility attributes that the underlying primitive already handles.**
| Component | What Radix handles |
| ----------------------------- | -------------------------------------------------------------------------------- |
| `Dialog`, `AlertDialog` | `role="dialog"`, `aria-modal`, focus trapping, ESC to close |
| `DropdownMenu`, `ContextMenu` | `role="menu"` / `role="menuitem"`, arrow key navigation |
| `Select` | `role="combobox"`, `aria-expanded`, keyboard selection |
| `Tabs` | `role="tablist"` / `role="tab"` / `role="tabpanel"`, `aria-selected`, arrow keys |
| `Checkbox` | `role="checkbox"`, `aria-checked`, Space to toggle |
| `RadioGroup` | `role="radio"`, `aria-checked`, arrow key navigation |
| `Switch` | `role="switch"`, `aria-checked`, keyboard toggle |
| `Tooltip` | Trigger/content association, show/hide timing |
| `Accordion`, `Collapsible` | `aria-expanded`, Enter/Space to toggle |
| `Popover`, `HoverCard` | Focus management, dismiss on ESC |
| `Slider` | `role="slider"`, `aria-valuemin/max/now`, arrow keys |
| `Toggle`, `ToggleGroup` | `aria-pressed`, keyboard support |
| `ScrollArea` | Accessible scrollbar replacement |
| `NavigationMenu` | `role="navigation"`, keyboard navigation |
Specifically, never flag: missing `role` on Radix-based components; missing `aria-modal` on `Dialog`/`AlertDialog`; missing `aria-expanded` on `Accordion`, `Collapsible`, `Select`, or `DropdownMenu` triggers; missing `aria-selected` on `Tabs`; missing `aria-checked` on `Checkbox`, `RadioGroup`, or `Switch`; missing keyboard handlers on interactive Radix components; missing focus management in dialogs; missing `aria-label` on `DialogContent`'s built-in close button (it renders `<span className="sr-only">Close</span>`; standalone icon-only `<DialogClose>` still needs an accessible name).
**Do** flag accessibility issues on:
1. **Custom interactive elements** not using Radix primitives (e.g. a `<div onClick>` that should be a `<button>`)
2. **Icon-only buttons** missing an accessible label — `<Button>` alone does not add one; use `aria-label` or `<span className="sr-only">`
3. **Missing `Label` association** — form inputs need a label bound either via explicit `htmlFor`/`id` (`<Label htmlFor="x">` + `<Input id="x">`, or `FormItemLayout` with `isReactForm={false}` whose rendered `htmlFor` matches the input's `id`) or via RHF context (`<FormField>` + `<FormItem>`/`FormItemLayout` + `<FormControl>`); `<Field>` alone and `name` attributes do not associate labels
4. **Images missing `alt` text**
5. **Color-only state indicators**