|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Guidance for AI coding agents in this repo. Human contributors: see the |
| 4 | +[Contribute](./README.md#contribute) section of the README. |
| 5 | + |
| 6 | +This is `file-selector`: it converts a `DragEvent`, a file `input`, a paste, or a File System |
| 7 | +Access API selection into a flat list of `File` objects (`fromEvent`). It is a small, published npm |
| 8 | +library written in TypeScript with no runtime dependencies; keep it that way. The full MIME table is |
| 9 | +split into the `file-selector/mime` subpath export so it stays out of the core bundle - a |
| 10 | +`size-limit` budget guards against it leaking back in. |
| 11 | + |
| 12 | +The toolchain is the Rust-based oxc stack: [oxlint](https://oxc.rs/) to lint, |
| 13 | +[oxfmt](https://oxc.rs/) to format, [tsdown](https://tsdown.dev/) (Rolldown + oxc) to build and emit |
| 14 | +declarations, and [Vitest](https://vitest.dev/) to test; TypeScript (`tsc --noEmit`) type-checks and |
| 15 | +`size-limit` budgets the bundle. Browser behaviour is covered by [Playwright](https://playwright.dev/) |
| 16 | +(library e2e), and the [Vocs](https://vocs.dev/) docs site has its own Playwright smoke test. There |
| 17 | +is no Babel, ESLint, Prettier, or Rollup; do not reintroduce them. |
| 18 | + |
| 19 | +## Workflow |
| 20 | + |
| 21 | +- Clarify the design before implementing. For anything non-trivial, agree on the approach first. |
| 22 | +- One unit of change per commit. Never mix unrelated changes. Present the change for review before |
| 23 | + committing. |
| 24 | +- Every change ships with tests. Run local CI before calling it done, and do not claim it passes |
| 25 | + without running it. |
| 26 | +- Verify against the code and the tools: read before you answer, run before you assert. |
| 27 | + |
| 28 | +Local CI (must be green before review): |
| 29 | + |
| 30 | +```shell |
| 31 | +npm run type-check # tsc --noEmit |
| 32 | +npm run lint # oxlint |
| 33 | +npm run lint:type-aware # oxlint --type-aware (non-blocking in CI, but run it) |
| 34 | +npm run format:check # oxfmt --check |
| 35 | +npm run build # tsdown -> dist/ |
| 36 | +npm run test:cov # vitest with coverage |
| 37 | +npm run size # size-limit bundle budget |
| 38 | +``` |
| 39 | + |
| 40 | +The prek git hooks (installed via `npm install`) auto-run oxfmt and oxlint on staged code and |
| 41 | +validate the commit message, but they do not run type-check, the build, or the tests, and they do |
| 42 | +not format Markdown. Run the commands above yourself, and run `npm run format` after editing |
| 43 | +docs/Markdown or CI's `format:check` will fail on it. |
| 44 | + |
| 45 | +Browser tests need Chromium (`npx playwright install --with-deps chromium`): |
| 46 | + |
| 47 | +```shell |
| 48 | +npm run test:e2e # library: file-input selection + CDP drag-and-drop in real Chromium |
| 49 | +npm run test:docs:e2e # docs hydration smoke (run when you touch the docs or a docs dependency) |
| 50 | +``` |
| 51 | + |
| 52 | +## Writing: code, comments, docs, commits |
| 53 | + |
| 54 | +- Concise and to the point. No fluff. Explain the non-obvious; do not narrate the obvious. |
| 55 | +- ASCII only. No em-dash and no `--`; write `-`. Use `->` not the arrow glyph, `!=` not the |
| 56 | + not-equal glyph, and so on. |
| 57 | +- Comments justify _why_, not _what_. Delete any comment that restates the code. |
| 58 | +- Formatting is not a matter of taste: oxfmt owns it. Run `npm run format` rather than |
| 59 | + hand-formatting. House style (`.oxfmtrc.json`) is double quotes, two-space indent, semicolons, no |
| 60 | + trailing commas, no bracket spacing (`{a, b}`), arrow parens omitted when possible, and a |
| 61 | + 120-column print width. |
| 62 | + |
| 63 | +## Commits |
| 64 | + |
| 65 | +- [Conventional Commits](https://www.conventionalcommits.org/); the type set is enforced by a |
| 66 | + commit-msg hook and consumed by semantic-release. Write the subject in the present tense, |
| 67 | + imperative voice: `fix: handle empty DataTransfer`, not `fixed` or `fixes`. |
| 68 | +- `feat:`/`fix:`/`perf:` cut a release; `feat!:` or a `BREAKING CHANGE:` footer cuts a major. |
| 69 | + `chore:`/`ci:`/`docs:`/`test:`/`refactor:`/`style:`/`build:` do not. Pick the type with that in |
| 70 | + mind. |
| 71 | +- Keep the body minimal, or omit it. A good subject plus the diff is usually enough; add a body only |
| 72 | + for what the code cannot show (why, a trade-off, a non-obvious consequence). Never restate the |
| 73 | + change or narrate the diff. |
| 74 | +- Disclose AI with an `Assisted-by: Claude:claude-opus-4-8` trailer. Never `Co-Authored-By`, and |
| 75 | + never add a human's `Signed-off-by`. |
| 76 | + |
| 77 | +## Tests |
| 78 | + |
| 79 | +- Unit tests live beside the source as `src/*.spec.ts` and run under Vitest with the jsdom |
| 80 | + environment. Assert on real `File`/`DataTransfer` shapes rather than mocking the DOM where a real |
| 81 | + object will do. |
| 82 | +- `e2e/*.e2e.ts` are Playwright tests for library behaviour that only a real browser exercises: |
| 83 | + file-input selection and CDP-driven drag-and-drop against a fixture page that imports the built |
| 84 | + `dist/` (so `npm run build` runs first via `pretest:e2e`). |
| 85 | +- `e2e-docs/*.e2e.ts` are Playwright smoke tests for the docs _site_ (hydration), run through the |
| 86 | + separate `playwright.docs.config.ts`. See "Docs site" below. |
| 87 | +- Coverage must not drop. New code ships with tests that hold or raise it. Measure with |
| 88 | + `npm run test:cov`. |
| 89 | + |
| 90 | +## Code conventions |
| 91 | + |
| 92 | +- Source is TypeScript (ESM); no JSX - this is a DOM utility, not a UI component. |
| 93 | +- The published API is exactly what `src/index.ts` re-exports, plus the `file-selector/mime` subpath |
| 94 | + (the MIME table). Keep the MIME table on that subpath so `size-limit` stays green, and keep the |
| 95 | + README usage examples in step with any public change. |
| 96 | + |
| 97 | +## Build and publish |
| 98 | + |
| 99 | +- `npm run build` bundles with tsdown into `dist/` (ESM `.js`, CJS `.cjs`, and `.d.ts` emitted from |
| 100 | + source), with two entries: the core (`index`) and the MIME table (`mime`). Do not hand-edit |
| 101 | + anything in `dist/` - it is generated. |
| 102 | +- What ships to npm is the `files` allowlist in `package.json` (`dist` and `src`, minus specs); keep |
| 103 | + it accurate. The `size-limit` budget in `package.json` fails the build if the core entry grows - |
| 104 | + usually a sign the MIME table leaked out of its subpath. |
| 105 | +- Releases are automated by semantic-release from the commit history; the repo version stays |
| 106 | + `0.0.0-development` and is set at publish time. Never bump the version by hand. Runtime is Node |
| 107 | + `>= 22` (`engines`). |
| 108 | + |
| 109 | +## Docs site |
| 110 | + |
| 111 | +- Docs are MDX under `docs/` with `vocs.config.ts`; `npm run docs:build` emits fully static HTML to |
| 112 | + `site/` (gitignored) under the `/file-selector` basePath, and the Pages workflow (`pages.yml`) |
| 113 | + deploys it to https://react-dropzone.github.io/file-selector/. |
| 114 | +- Vocs runs on waku, whose `unstable_*` router APIs break between beta releases. `waku` is pinned |
| 115 | + (and ignored in Dependabot) to the version Vocs supports; bumping it can white-screen the site |
| 116 | + (regressed by #177). Do not unpin without re-running the docs smoke test. |
| 117 | +- `e2e-docs/docs-smoke.e2e.ts` loads key routes in headless Chromium and fails on a hydration crash |
| 118 | + or a blank page. The `docs-e2e` CI job runs it on every PR; `docs-monitor.yml` runs it on a |
| 119 | + schedule against production. This is the guardrail for the failure class above - keep it working. |
| 120 | + |
| 121 | +## CI workflows |
| 122 | + |
| 123 | +- GitHub Actions live in `.github/workflows` (`test.yml` runs lint/test/size/e2e/docs-e2e; |
| 124 | + `pages.yml` builds and deploys the docs; `release.yml`; `docs-monitor.yml`). Write the workflow |
| 125 | + `name:`, every job name, and every named step in Sentence case (match the existing files). |
| 126 | +- Dependabot groups patch/minor bumps and auto-merges patches on green CI (`.github/dependabot.yml`, |
| 127 | + `dependabot-auto-merge.yml`). Auto-merge trusts CI, so any check that must gate a dependency bump |
| 128 | + has to run in CI - that is why the docs smoke test exists. |
| 129 | +- Keep workflows minimal and scoped to one purpose; prefer the built-in `GITHUB_TOKEN` over a |
| 130 | + personal access token. |
0 commit comments