Skip to content

Latest commit

 

History

History
171 lines (135 loc) · 19.5 KB

AGENTS.md

File metadata and controls

171 lines (135 loc) · 19.5 KB

Agent instructions for docs-engine

This file is for AI coding agents working in this repository, and for the people directing them. It records the conventions, constraints, and review feedback that apply to every change, so the same feedback never has to be given twice. Read README.md and ARCHITECTURE.md first for what the engine is and how it fits together.

What this repository is

  • The rendering engine for Coder's documentation, published as the @coder/* packages under packages/ and deployed by the apps under apps/.
  • The documentation content lives in coder/coder under docs/, not here. Content fixes go to that repository.
  • The code-server docs come from coder/code-server's docs/ at the commit apps/docs/code-server-docs.json pins, and only the mainline carries them. Their content fixes go to that repository; bump the pin here in a reviewed PR.
  • apps/docs is the public docs site (served at coder.com/docs), apps/router serves the per-version archive, apps/offlinedocs is the offline export, and apps/dist-release packs the package tarballs and builder kit that a v* tag publishes as this repository's GitHub Release.

Hard constraints

  • Never publish a package to the public npm registry. The @coder/* packages stay private; public releases are GitHub Release assets on this repository, built by release-dist.yml through apps/dist-release only, and consumers such as coder/coder's offlinedocs/ pin those asset URLs.
  • The public site's Content Security Policy is script-src 'self' 'unsafe-inline'. Adding any third-party origin (script, frame, or connect) needs sign-off from Security (Lisa or JD). Write such a change behind a flag and mark it "needs security sign-off" in the PR.
  • No layout shift. Any change to the page chrome must keep cumulative layout shift at 0 through load, hydration, hover, and toggling.
  • The site is served under a base path in production (/docs, and /docs/vX.Y, /docs/@vX.Y.Z or /docs/@main for the other versions) but from the root on previews. Never hard-code a root-absolute asset URL (/brand/..., /images/...) in CSS or components; derive it from the base path. A root-absolute URL works on previews and breaks in production.
  • Never import a client component into apps/docs/lib/sources.ts, and keep the generated-collection imports after the package imports there. Doing otherwise once doubled a 60 MB server chunk. apps/docs/scripts/source-import-order.test.mjs pins the order, so keep Oxfmt's sortImports off and add no import-sorting lint rule.
  • Public docs follow coder.com's design system (packages/ui/styles/tokens.css and ramps.css in coder/coder.com-new). In-product docs may use Coder Kit tokens instead.
  • Never authorize a Vercel deployment of a fork's pull request. Vercel's Git fork protection holds those deployments until someone authorizes them, and a fork's build would run with the project's environment variables. Fork previews go only through the reviewed docs-preview environment in Actions.

Working in the repository

  • Never commit on main. Use one git worktree per branch, under .worktrees/<branch-name>, with branches named vigilante/<topic>.
  • Set up with pnpm install --frozen-lockfile, then pnpm turbo run build --filter='./packages/*'. Apps consume the packages' built dist/, so rebuild a package after changing it before testing it in an app.
  • Run pnpm run hooks once per clone, after installing. It points core.hooksPath at .githooks, which pnpm install does only where lifecycle scripts are allowed, and every worktree of the clone then uses it. The pre-commit hook checks the staged files with Oxfmt and Oxlint, Stylelint for packages/docs-theme CSS, and actionlint for workflows when it is installed. It only reports and never rewrites a file, and it reads the files on disk, so a partly staged file is checked as saved. Fix what it reports before committing rather than using --no-verify, since CI runs the same checks.
  • Format changed files with ./node_modules/.bin/oxfmt <files> and lint them with ./node_modules/.bin/oxlint <files>; pnpm lint runs both over the whole repository.
  • Stylelint checks the CSS in packages/docs-theme as part of that package's lint script, with stylelint-config-recommended only; formatting stays with Oxfmt, so add no Stylelint style rules.
  • For local dev against the real corpus, run pnpm dev in apps/docs with DOCS_REPO pointing at a coder/coder checkout. Without it, a small fixture corpus is used.
  • Stop a dev server by its port (kill $(lsof -ti tcp:<port>)). Never use pkill -f 'next dev', because other sessions run dev servers on the same machine.
  • Previews are behind Vercel SSO. Vercel builds apps/router from Git on main only, for production; git.deploymentEnabled in apps/router/vercel.json turns its Git builds off for every other branch, so a pull request gets no Vercel bot preview. A docs-site change is previewed by engine-pr-preview.yml, which runs on every push to a pull request from this repository that touches apps/docs, apps/offlinedocs or packages/, builds it against coder/coder main, and, once a docs-preview reviewer approves the deploy, comments the URL on the PR and links it from a docs preview status. The deploy job runs the PR's own copy of docs-pr-preview.yml beside VERCEL_TOKEN, so approving a preview means reviewing any .github/workflows/ change in that PR first.
  • A pull request that changes apps/router, docs-config or docs-manifest also gets a router preview from router-pr-preview.yml: it builds with vercel build --standalone and no Vercel credentials, and deploys once a docs-preview reviewer approves, then links the URL in a comment and a router preview status. It replaces the Vercel Git previews, which are off for every branch but main. The build writes coder-docs's project settings itself, so keep them in step with the Vercel project.

Code

  • Comments: at most one short line, and only where the reason is not obvious from the code. No explanatory comment blocks.
  • No Linear IDs (DOCS-123), review-round labels, or other ticket references in code, comments, or commit messages. Linear links belong in the PR body.
  • Write tests first where there is logic.
  • Test rendered output, not implementation details. Render into the jsdom DOM (see copyright.test.tsx for the pattern) and assert with DOM queries such as querySelector, classList, textContent, and style.getPropertyValue. Never parse HTML with regular expressions.
  • Client components import @coder/docs-config/client, never the package root, which bundles zod into every page; first-load:check in the docs site fails if zod comes back.
  • Prefer Fumadocs' own extension points (layout slots, components overrides, CSS tokens) over forking its components. When a fork is unavoidable, keep it minimal and note the source file and version in one line.

Accessibility

  • Aim for WCAG 2.2 AAA and never ship below AA. Text contrast is 7:1 where the design allows, 4.5:1 at minimum; non-text contrast (icons, borders that carry meaning) is 3:1.
  • Where coder.com's tokens fall short of AAA, the standard palette keeps the site's value as long as it meets AA, and the More contrast palette carries the AAA value.
  • Every interactive element has a visible :focus-visible state, a target of at least 24 by 24 CSS pixels (44 by 44 under pointer: coarse), and an accessible name.
  • Honour prefers-contrast: more and prefers-reduced-motion.
  • Colour never carries meaning alone; pair it with an icon or a label.
  • New UI must pass the axe pass (pnpm --filter @coder/docs-site a11y:axe), which CI runs on the fixture corpus. When a new component or content type ships, add a fixture page that exercises it and add the page to the pass.

Upstream Fumadocs

  • Consider every change as a possible upstream contribution to Fumadocs, and say yes or no, with the reason, in the PR's ## Upstream section.
  • Good candidates are generic bugs, accessibility fixes, and missing options in fumadocs-ui or fumadocs-core. Coder branding, routing, content, and our own CSS are not.
  • File upstream issues or PRs only after Nick approves them. When the Fumadocs maintainer declines an idea, ship it in our own code rather than waiting.

Commits

  • Conventional Commits: type(scope): imperative subject, lowercase, no trailing period, with a body that explains why.
  • The last line of every commit message is Assisted-by: AI. Never add a Co-Authored-By line for an AI, and never name an AI model, vendor, or product.

Pull requests

  • Open PRs as drafts unless told otherwise, with no reviewers. Nick decides per PR who reviews.
  • .github/CODEOWNERS names the @coder/docs team, so GitHub requests its review when a PR leaves draft. Don't name individuals there; change the team's membership instead.
  • Request Jess only for TypeScript changes, and Ben only when Nick asks.
  • Agents never merge, never approve, never dismiss reviews, and never run gh workflow run. When told not to comment on a PR, post nothing there.
  • Body sections, in order: ## Merge order, Summary, Design or Fix, ## QA, ## Pages to compare, Testing, ## Upstream, the Linear link, and then a --- rule followed by 🤖 Built with AI assistance. as the last line.
  • Write PR bodies, issues, review comments and commit messages as normal paragraphs, not one sentence per line. One sentence per line applies only to Markdown files (.md, .mdx).

QA sections

Nick merges after checking each PR in his own browser, so QA must work there:

  • Browser-only steps, with no terminal. Each step names the page, the exact action, and the expected result in plain words; DevTools values are optional extras.
  • Steps work in both Firefox and Chrome. Where DevTools differ, give both. Mark any Firefox step that could not be verified.
  • A ## Pages to compare table with the columns What to check, Production, and Preview. Both are full clickable URLs: production at https://coder.com/docs/<path>/ and the preview on the branch alias. Note that the preview alias always serves the PR's latest deploy and needs a Vercel login.
  • At most one before-and-after screenshot, for visible changes. Host it on an orphan branch pr-assets/<pr-number>-<topic> that is never merged, and embed it with https://github.com/coder/docs-engine/blob/<branch>/<file>?raw=true.
  • For CI, publish, or test-only changes, say there is nothing to see on the site and point to the GitHub or Vercel pages that show the change working.
  • Never put a Vercel share link or protection-bypass token in a PR body.
  • When editing a PR body, fetch it with gh pr view <n> --json body immediately before writing and apply only your change, so you never overwrite someone else's newer edit from a stale copy. Only one agent edits a given PR's body at a time.

Review feedback

Rules that came out of PR reviews, so reviewers don't have to repeat them. The number after each rule is the PR where it was raised.

Code and naming

  • Keep code comments minimal; the PR body carries the reasoning. Don't justify a change in a comment block, especially in CSS. (#114, #115, #116)
  • Put trade-offs, abandoned approaches, and non-obvious invariants in the PR body or ARCHITECTURE.md, with at most one short line in code, so no one re-attempts something already ruled out. (#28, #48, #52 to #55)
  • Don't name a local the same as a global, such as a helper called document, even where it's harmless. (#124)
  • When a function's purpose changes, rename it; when an implementation is superseded, move every caller and delete the old one. (#49)
  • Export shared constants and helpers from one place and import them everywhere, instead of keeping private copies. (#28, #44, #52)
  • Keep async behaviour consistent: a function never resolves synchronously for some inputs and asynchronously for others. (#131)
  • Avoid as unknown as and other casts that throw away type information, in code and tests. (#131, #161)
  • Build or recognise a version URL segment only through versionSegment, versionUrlPrefix and isVersionShapedSegment from @coder/docs-manifest/version-segment; version-segment-scan.test.ts fails on a hand-built one. (#201)

Tests

  • Never parse rendered HTML with regular expressions. Render into jsdom, or parse with DOMParser, and assert with DOM queries. (#131)
  • Assert on a component's rendered output and behaviour, never on its props or internal state, and don't cast an element to a fake type to inspect it. (#131, #161)
  • When the same jsdom setup repeats across test files, extract a shared helper. (#131)
  • Check that a new test fails against the old code before landing it. (#50)
  • For a security invariant, demonstrate the failure mode itself, such as the leaked content, not just that a code path exists. (#28, #49, #52 to #54)
  • Base corpus-shaped tests on real markup from the docs, not simplified examples. (#13, #28)
  • Back every documented invariant with a test that pins it. (#48, #53, #54)
  • Run any change that widens strict validation against the real corpus in strict mode before merging. (#50)
  • Name a test file after the module it covers (archive.test.ts), never after the PR or the batch it came from. (#232)
  • Every jsdom test preload calls guardDomAssertions() from @coder/docs-ui/test/assert-dom. A failing assertion on a React-rendered node can use all of the machine's memory, because Node diffs the node's whole fiber tree.
  • Assert with node:assert/strict, on one element's textContent or getAttribute at a time. Never assert directly on elements, NodeLists, HTMLCollections or objects holding elements. Never use t.assert or a bare node:assert import, which the guard doesn't cover; oxlint rejects the import but not t.assert.

Security and content handling

  • Fail closed: reject ambiguous or unsafe input, and throw when a size or shape can't be determined, instead of assuming it's safe. A checker that meets a shape it can't parse reports it rather than passing. (#28, #51, #347)
  • Refuse up front the input an upstream is known to reject, and treat its error statuses as failures (503) rather than misses (404): a crawler reads a 404 as gone and a 503 as try again. Never let a response produced from an error be cached. (#232)
  • When a reader tolerates one bad item, it keeps that item's last good value instead of dropping it, and refuses the refresh when nothing good is left for an item the site depends on. (#232)
  • CSS alone never gates or hides content. If gating is incomplete, say so. (#28, #49)
  • Surface authoring defects at sync or build time rather than swallowing errors at runtime. (#28, #44)
  • When scanning HTML, treat raw-text elements (script, style, textarea, title) as text, and keep that list the same in every scanner. (#52, #53)
  • Never let one caller's temporary state live in another caller's directory or address space. (#51)
  • Keep every Actions secret in an environment with a branch rule, a tag rule or a required reviewer, never at repository level: a workflow pushed to any branch can read a repository secret or an unprotected environment's, with no pull request and no review. docs-dist deploys only from v* tags, which only admins can create, and its release job holds no secret, only its own GITHUB_TOKEN with contents: write. (#342, #343)
  • A job that reads a secret declares its environment:. The only exceptions are a guard step listed by job and step name in GUARDS in apps/docs/scripts/workflow-secrets.test.mjs, which fails if a write secret is visible, and a secrets: inherit call to a workflow in this repository. That test enforces this, and fails on any secret reference it can't place in a job. (#342, #343, #347, #325)
  • Treat vercel.json and .github/workflows/ as a deploy boundary: review any change to git.deploymentEnabled, an environment name, a trigger or a secret reference line by line, because a reformatted file can hide a one-line change. (#343)

Accessibility and UI

  • Mark the current item (a nav or TOC entry) with aria-current, not only with a visual style. (#121)
  • When a status such as "404" is only visual, add visually hidden text so screen readers get it too. (#126)
  • Use an icon that implies behaviour, such as the external-link icon, only when the element behaves that way. (#123)

CI and scripts

  • The branch ruleset requires one check, build & check, which is the aggregator job at the end of ci.yml. Add new CI work as its own job in that job's needs: list, and never give another job that name.
  • build & check passes when every job it needs succeeded or was skipped, and fails when any failed or was cancelled, as coder/coder's required job does.
  • The a11y job runs the axe pass over the fixture build and fails on any WCAG violation not in .github/a11y-allowlist.json. Allowlist a failure only under the open PR that fixes it (pr-<n>) or, when the fix has no PR yet, a tracked-<topic> owner; never under a Linear ID.
  • Adding a fixture page can need updates elsewhere: fixtures/url-parity-approved.json for a classic anchor the page drops on purpose, and the axe page list in scripts/a11y-axe-helpers.mjs.
  • A new package with a test script goes in the test matrix in ci.yml; the test matrix covers every package job fails until it does.
  • The workspace, CI and Vercel run Node 24, but the released packages and the offline kit support Node 22.12 and later, tested on 22.23.4, which coder/coder's toolchain pins. The release rewrite in apps/dist-release/src/manifest.mjs stamps engines.node: ">=22.12", and the packages on node 22 job builds, tests and exports on 22, so use no Node-24-only API in packages/ or apps/offlinedocs.
  • Oxfmt formats the YAML too: the workflows, .github/actions/setup/action.yml and pnpm-workspace.yaml, but not pnpm-lock.yaml, which pnpm writes.
  • The actionlint job lints every workflow, with ShellCheck over the run: scripts. Run it locally with pnpm lint:actions, which needs actionlint and shellcheck on your PATH (brew install actionlint shellcheck).
  • Fix what actionlint reports; for a ShellCheck false positive, put # shellcheck disable=SCnnnn # <reason> on the line before the command.
  • Pin LC_ALL=C for any sort whose output must match byte for byte across jobs. (#125)
  • Normalise a shared config value, such as the base path, with the same function in every script that reads it. (#107)
  • Give every fetch in a polling or health-check script a per-request timeout (AbortSignal.timeout). (#107)
  • Don't write input || default in GitHub Actions expressions where 0 or another falsy value is valid. (#105)
  • When partitioning entries with fixed filters, add a catch-all bucket or assert that the parts add up to the whole. (#105)

Branches and PRs

  • Plan large or speculative work as a series of small, focused PRs. (#101)
  • Before rebasing a stale branch, check whether newer work has superseded it, and keep only what's still new. (#44)
  • When two PRs touch the same code, land the fix first and rebase the other onto it, so conflict resolution can't silently undo the fix. (#50, #53)
  • When review feedback is applied, say so in the PR so the thread isn't left ambiguous. (#28)

Keeping this file current

  • When Nick gives a new standing instruction, or a reviewer leaves feedback that generalises beyond one PR, add it here in the same PR or a follow-up, under the right section, with the source PR number for review feedback.
  • Before starting work, read the review comments on any PR you are about to change, and check this file for the rule before asking.
  • Keep entries short and imperative. Remove entries that stop being true, and resolve conflicting entries rather than keeping both.