Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# The kit is small, so one job type-checks, tests, builds and packs it. Two
# sites build on it, which is why the pack check matters: it runs `pnpm pack`
# and reads the tarball, so a file missing from the published package fails
# here and not in a consumer's build.
#
# The pack check fails a file missing from the published package here, not in a consumer's build.
# `Full CI` is the one required check, a roll-up of the jobs below.
#
# A run that Dependabot starts is held: every job a pull request can start is
# skipped, so it uses no runner, and no `Full CI` is reported, so the required
# check stays expected and blocks a merge. To opt a pull request in, start a run yourself with `gh pr ready --undo <n> && gh pr ready <n>`, or
# push to its branch. Rerunning a held run keeps Dependabot as the actor.
# A run that Dependabot starts is held: its jobs are skipped and no `Full CI` is reported, so the required check blocks the merge (`AGENTS.md` says how to start one).
# Rerunning a held run keeps Dependabot as the actor.
name: CI

on:
Expand All @@ -21,12 +14,8 @@ on:
workflow_dispatch:

concurrency:
# A push to `main` or a manual run gets a group of its own, so a later push
# never cancels the verdict on a commit; only a pull request's run is
# superseded. A draft and a ready pull request have groups of their own: a
# draft pushed and marked ready a moment later starts two runs, and in one
# group the later queued run cancels the other, which can leave `Full CI`
# unreported.
# Only a pull request's run is superseded. A draft and a ready pull request have groups of their own: a draft marked ready
# a moment after a push starts two runs, and in one group the later queued run cancels the other, which can leave `Full CI` unreported.
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'pull_request' && format('{0}-{1}', github.ref, github.event.pull_request.draft && 'draft' || 'ready') || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

Expand All @@ -42,6 +31,8 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# check-comments diffs the pull request against its base.
fetch-depth: 0
persist-credentials: false
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
with:
Expand All @@ -51,19 +42,21 @@ jobs:
node-version: 22
cache: pnpm

- if: ${{ github.event_name == 'pull_request' }}
run: node scripts/check-comments.mjs
env:
BASE: ${{ github.event.pull_request.base.sha }}
HEAD: ${{ github.event.pull_request.head.sha }}
- run: node --test scripts/check-comments.test.mjs
- run: pnpm install --frozen-lockfile
- run: pnpm types:check
- run: pnpm test
# The build writes `dist/`, which the pack check reads.
- run: pnpm build
- run: pnpm pack:check

# The one required check. A skipped job satisfies a required check, so this
# job turns the result of the others into one verdict. On a draft it is named
# `Draft CI`, so the required `Full CI` stays expected, which blocks a merge,
# until the run that marking the pull request ready starts has finished. It
# runs after a failed job and fails then; a cancelled run skips it, and a
# skipped job never reports as `Full CI`, so a cancel cannot leave it green.
# A skipped job satisfies a required check, so this turns the others' results into one verdict. On a draft it is named `Draft CI`,
# so `Full CI` stays expected until the run that marking ready starts has finished. A cancelled run skips it, and a skipped job never reports as `Full CI`.
gate:
name: ${{ github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' && 'Held CI' || (github.event.pull_request.draft && 'Draft CI' || 'Full CI') }}
needs: [build]
Expand Down
13 changes: 3 additions & 10 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: CodeQL

# A pull request or a push to `main` that changes only documentation or agent
# instructions starts no run. CodeQL is not a required check, so a run that
# never starts leaves no check pending. A draft pull request is analyzed once
# it is marked ready for review, and on every push after that. A weekly run
# analyzes the whole tree.
# A change to only documentation or agent instructions starts no run, which is fine because CodeQL is not a required check. A draft is analyzed once marked ready.
on:
push:
branches: [main]
Expand Down Expand Up @@ -34,9 +30,7 @@ on:
- cron: "41 4 * * 1"

concurrency:
# A draft and a ready pull request have groups of their own, so a draft's
# run, queued a moment after the ready one, never cancels it. A push to
# `main` gets a group of its own, so a later push never cancels its run.
# A draft and a ready pull request have groups of their own, so a draft's queued run never cancels the ready one. A push to `main` has its own too.
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'pull_request' && format('{0}-{1}', github.ref, github.event.pull_request.draft && 'draft' || 'ready') || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

Expand All @@ -46,8 +40,7 @@ permissions:
jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Public repositories can scan without a paid Code Security license. A run
# that Dependabot starts on a pull request is held, as `ci.yml` says.
# Public repositories scan without a paid license. A run Dependabot starts is held, as `ci.yml` says.
if: ${{ !(github.event_name == 'pull_request' && github.actor == 'dependabot[bot]') && github.event.repository.private == false && !github.event.pull_request.draft }}
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/pr-description.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Pull request description

# GitHub cannot require the pull request template, and a body passed from the
# command line skips it, so this check does. It is its own workflow so that
# editing a description reruns only this and never `ci.yml`.
# Its own workflow, so editing a description reruns only this and never `ci.yml`.
on:
pull_request:
branches: [main]
Expand All @@ -18,8 +16,7 @@ permissions:
jobs:
description:
name: Pull request description
# A skipped job satisfies a required check, so a bot's pull request
# (Dependabot and the like) passes without a description.
# A skipped job satisfies a required check, so a bot's pull request passes without a description.
if: ${{ github.event.pull_request.user.type != 'Bot' }}
runs-on: ubuntu-latest
timeout-minutes: 2
Expand All @@ -32,5 +29,4 @@ jobs:
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
# The body is read from the event file, never put on a command line.
- run: node scripts/check-pr-description.ts
15 changes: 3 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
# Publishes a version. Push a tag `v<version>` that matches `package.json`:
# the workflow builds the package, attaches the tarball to a GitHub release,
# and publishes it to npm.
#
# The GitHub release comes first and is the install source until npm has the
# package: a site depends on the release's tarball URL. npm publishes with
# trusted publishing (OIDC), so no token is stored. The first version of a
# package cannot be published that way, because trusted publishing is set up
# on a package that exists, so the first version is published by hand and the
# `publish` job skips a version npm already has.
# Push a tag `v<version>` that matches `package.json`.
# The GitHub release comes first and is a site's install source until npm has the package. Trusted publishing is set up on an existing package,
# so a package's first version is published by hand, and the `publish` job skips a version npm already has.
name: Release

on:
Expand Down Expand Up @@ -68,7 +61,6 @@ jobs:
path: ${{ runner.temp }}/pack/*.tgz
if-no-files-found: error

# A version with a hyphen (`0.0.1-alpha.0`) is a prerelease.
- name: Create the GitHub release
env:
GH_TOKEN: ${{ github.token }}
Expand Down Expand Up @@ -112,7 +104,6 @@ jobs:
echo "@withmarfa/docs-kit@${VERSION} is already on npm, so there is nothing to publish."
exit 0
fi
# A prerelease takes `latest` while npm has no stable version, so
# `latest` never points at an older prerelease.
current="$(npm view @withmarfa/docs-kit dist-tags.latest 2>/dev/null || true)"
case "${VERSION}" in
Expand Down
32 changes: 30 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- Make worktrees in `.claude/worktrees/` (`git worktree add .claude/worktrees/<name> -b <branch> origin/main`). Remove the worktree and its branch once the work is merged.
- This repository is public. Commit no internal hostname, private IP address, personal path, key or token.
- CI holds a run that Dependabot starts on a pull request: its jobs are skipped, so no `Full CI` is reported and the required check blocks the merge. To run it, use `gh pr ready --undo <n> && gh pr ready <n>`, or push to the branch. A new job that a pull request can start needs the same condition.
- A comment says only what the code cannot: the reason, the constraint or the trade-off.
- Comments follow [Comments](#comments).
- The kit sends nothing about itself. `Analytics` loads PostHog only when a site passes it a key, and the SDK stays in its own chunk, never in a site's entry chunk.
- Classes and custom properties are prefixed `docs-kit-` and `--docs-kit-`, so they never meet a site's own.

Expand All @@ -29,9 +29,35 @@
- `src/components/` and `src/lib/`: the code behind the entries. A test sits beside the file it tests.
- A client entry (`index.ts`, `mdx.ts`) never reaches `fumadocs-core/mdx-plugins` or a `node:` import: a site's dev server loads modules one by one and the page fails to hydrate. `src/entries.test.ts` builds the entries and checks. Put build-time code in `config.ts`.
- `styles.css`: the design tokens and Fumadocs overrides. A `.prose` rule that reaches into the body keeps the plugin's `not-prose` guard (`src/styles.test.ts` checks). It scans `dist/` for Tailwind classes, so build before you test a site against it.
- `scripts/`: the pack check and the pull request description check.
- `scripts/`: the pack check, the pull request description check and the comment check.
- `dist/`: the build, never committed.

## Comments

The code is the source of truth. Code that reads well matters more than explanation around it. A comment says only what the code cannot, and when in doubt, it goes.

A comment stays for these four reasons only, each in as few lines as it needs:

1. **A constraint from outside:** Fumadocs, Vite, React, TanStack Start, Cloudflare Workers or wrangler, Orama, PostHog, MDX or remark, or a browser. Check the claim for the version in `pnpm-lock.yaml` before you write it (the package source, its docs or a quick test), and name the version or link the source. A claim that cannot be settled cheaply is not written, unless it guards working code. Then one line says what not to replace that code with, and the claim goes to an issue.
2. **A trap the code cannot carry:** an ordering, a race, a guard, a fallback, or why a CI job or step is shaped as it is, that a competent agent reading only the code would "fix" and break. Try a name, a type, an assertion or a test first. In tests, this includes why a wait or a fixed clock is needed, and the witness of a test that asserts absence.
3. **TSDoc on the exports of the entries** (`index.ts`, `server.ts`, `mdx.ts`, `config.ts`, `vite.ts`, `page-limits.ts`): what a site needs, as a one-line summary, then a refusal or a non-obvious condition. Not how the kit does it. Internal items get no doc comment; a trap there is a plain `//` line.
4. **A comment a tool requires,** such as a lint or `@ts-expect-error` reason, a `@vitest-environment` line or a license header.

Everything else has a better home, and one fact lives in one place:

| What | Where |
| --------------------------------------------------------- | ---------------------------------------------- |
| What the code does | The code: names, types and structure |
| What must stay true | A type, an assertion or a test |
| What a site needs to wire | The entry's doc comments and the `README.md` |
| Why it was built, and what is left to do | The issue |
| How a change was made, and a reviewer's question answered | The pull request and its commits |
| A convention or trap across the repository | This file |

So never: narration or restating, history ("previously", "no longer", "used to"), our issue numbers, people, `TODO` or `FIXME` (file an issue), a paragraph where one line does, or text repeated between a type and its members.

`scripts/check-comments.mjs`, run by the `build` job in `ci.yml`, fails a change whose added whole-line comments carry one of our issue or pull request numbers, `TODO` or `FIXME`, "previously" or "used to be", or that leave a TSDoc paragraph of more than four prose lines. Lists, tags and code blocks do not count as paragraphs. `dist/`, Markdown and agent files are not checked, and `scripts/check-comments.test.mjs` pins the rules. A pattern cannot catch everything this section bans, so review holds the rest.

## Commands

```bash
Expand All @@ -40,6 +66,7 @@ pnpm types:check # tsc --noEmit
pnpm test # vitest
pnpm build # tsdown, to dist/ with declarations
pnpm pack:check # packs the package and reads the tarball
node --test scripts/check-comments.test.mjs # the comment check's rules
```

- A change a site will notice runs against a site before it is merged: pack the kit (`pnpm pack`) and add the tarball to the site with `pnpm add file:<path>`. Never commit a `file:` dependency in a site.
Expand All @@ -60,3 +87,4 @@ Report only a problem you can show: name the file, input or site, and what goes
- **Unpacked file.** Flag a file a site needs at runtime that `files` or `exports` in `package.json` leaves out of the tarball.
- **Private detail committed.** Flag a token, key, internal hostname or personal path in a tracked file.
- **Stale instructions.** Flag a change that leaves an `AGENTS.md`, the README or a comment untrue, and fix it in the same pull request.
- **Comments.** Flag a comment that [Comments](#comments) bans, and an explanation added to answer a review: the answer belongs in the pull request. Flag a cut comment that guarded a trap or an outside constraint, or an entry's public doc that loses a refusal or condition a site needs.
Loading
Loading