Skip to content

Latest commit

 

History

History
126 lines (96 loc) · 15.8 KB

AGENTS.md

File metadata and controls

126 lines (96 loc) · 15.8 KB

Marfa docs

The source of the public documentation site at docs.marfa.so and the status page at status.marfa.so: Fumadocs on TanStack Start, deployed as two Cloudflare Workers. The docs follow the contract and the API description in withmarfa/marfa, which are the source of truth (STYLE.md, "Truth").

Instruction files

  • Before adding, moving or wiring a page under content/docs/, read content/AGENTS.md. Before writing one, read STYLE.md, the one place the writing rules live.
  • Before changing src/, read src/AGENTS.md: the agent surfaces, analytics and the status page.
  • Each AGENTS.md has a CLAUDE.md symlink beside it. Edit the AGENTS.md, never the link.
  • Put no .md file under content/docs/. The docs collection reads every .md and .mdx file there as a page, so an instruction file there fails the build for want of frontmatter, or is published.

Conventions

  • American English in code, comments and commits. Pages follow STYLE.md.
  • Conventional Commits with a scope, such as docs(build): or fix(mcp):. Work reaches main only through a pull request, one logical change each.
  • Make worktrees in .claude/worktrees/ (git worktree add .claude/worktrees/<name> -b <branch> origin/main). Once the work is merged, remove the worktree and its local branch (git worktree remove, then git branch -D, because git sees a squash-merged branch as unmerged) and run git pull --ff-only on main. If git refuses a removal, report it rather than forcing it.
  • TypeScript and ESM. pnpm with the committed lockfile, on Node 22.22.2 or later (24.15 or later on Node 24), which jsdom, the component tests' DOM, requires; TanStack Start, Vite and Vitest need only 22.12. CI uses Node 22.
  • This repository is public. Commit no internal hostname, private IP address, personal path, key or token, in a page or anywhere else.
  • A comment says only what the code cannot: the reason, the constraint or the trade-off. It never names a tracker, ticket number or project phase.
  • The telemetry page (/run/telemetry) starts with what Marfa shows its owner itself (marfa attention, the server's log, a webhook on attention.raised) and comes to destinations last. PostHog is one optional route for a power user (a free PostHog Cloud project and two settings), never part of Marfa: Marfa sends nothing about itself until its owner sets where.
  • A code change in another repository opens a docs issue here, not a docs pull request. Pages are rewritten whole from those issues after each Marfa release ("Docs pass at each release").
  • Each page has a kind and a job line. pnpm test fails a page over its kind's word ceiling or caps, and a page with no job line. STYLE.md, "Page types", says what each kind holds, and src/lib/page-limits.json sets the numbers. It also lists each page with a bigger budget and its reason.

Layout

  • content/docs/: the pages, one folder per tab, ordered by meta.json files.
  • src/routes/, src/lib/ and src/components/: the docs site, built on @withmarfa/docs-kit (the shared look and plumbing; src/AGENTS.md says which parts are the kit's), including the Worker entry src/server.ts, the Markdown copies, llms.txt, the docs MCP server at /mcp and the JSON addresses under /api/docs/.
  • src/status/: the status page, a second Vite target built by vite.status.config.ts into dist-status/ and deployed from wrangler.status.jsonc.
  • src/generated/ and openapi.json: written only by the sync scripts. Never edit them by hand.
  • scripts/: the sync from marfa, the sync of WithMarfa's plugins from withmarfa/plugins, the changelog sync and the staleness report. The changelog sync and the report use only Node built-ins, because CI runs the report without installing anything. Their tests are in src/lib/, the only place Vitest looks.
  • .github/scripts/: the CI change classifier and the publish checks, each with a .test.sh beside it, and the two sync scripts' tests.
  • public/: static files for both targets.

Commands

pnpm install          # also generates .source/
pnpm dev              # the docs site, http://localhost:3000
pnpm exec vite dev -c vite.status.config.ts   # the status page, port 3001
pnpm build            # the docs site, with a full prerender
pnpm build:status     # the status page
pnpm types:check      # fumadocs-mdx, then tsc for each target
pnpm test             # vitest, including the content lint and MCP conformance
bash .github/scripts/<name>.test.sh   # the tests for one shell script
  • Run pnpm build and pnpm build:status before pnpm types:check. Each build generates a route tree, and both trees register paths in one global interface, so without both builds the other target's route types become undefined.
  • pnpm deploy is a pnpm built-in that does not run the script. The fallback when Publish cannot deploy is pnpm run deploy or pnpm run deploy:status from an authenticated shell.

Syncing from marfa

MARFA_ROOT=/path/to/marfa scripts/sync-from-marfa.sh   # defaults to ../marfa
  • Use a marfa checkout on an up-to-date main with its tags fetched. The script copies committed files and runs nothing, and it checks every input before it writes anything. Its header lists what it writes.
  • After an API, glossary, CLI, contract table or release change lands in marfa, run the sync and open a sync pull request. A code change opens a docs issue, not a docs pull request (STYLE.md, "Keeping pages current").
  • Fix a gap in openapi.json or a generated table in marfa's generator, never here.
  • The script takes only what marfa generates and commits: a file of its own, Markdown between markers, or a committed data file such as builtin_catalog.json and the schemas in openapi.json, which it renders into tables and lists under labels with no sentence of its own. What a value means is written on the page that includes the file. A list marfa does not generate gets a source there first.
  • The script also writes the command tree, src/generated/cli-commands.json, from the same COMMANDS.md: every command with its options. src/lib/command-check.test.ts checks the pages' commands and options against it (STYLE.md, "Examples"), so a CLI change that renames or removes a command fails the next sync pull request on every page that still names it.
  • src/lib/glossary.test.ts holds the Glossary page to src/generated/GLOSSARY.md. src/lib/glossary-sources.json names, for each word on the page, the row that settles it and a fingerprint of the two definitions, so a sync that changes a row fails until the page's definition is read against it again and the fingerprint renewed.
  • After changing the script, run .github/scripts/sync-from-marfa.test.sh. It pins what the script writes and every input it refuses.

The connectors

MARFA_PLUGINS_ROOT=/path/to/plugins scripts/sync-from-plugins.sh   # defaults to ../plugins
MARFA_PLUGINS_TAG=v0.0.9 scripts/sync-from-plugins.sh              # a tagged release instead of main
scripts/sync-from-plugins.sh --relink                              # indexes and headers only, from the copy held
  • withmarfa/plugins holds WithMarfa's plugins: the connectors under connectors/, and common type families under types/, one folder each (Tickets is the first). The sync reads both, as that repository's own list does (scripts/release/plugins.ts): each connectors/<name>/plugin/plugin.json, and each types/<name>/ that holds a plugin.json. A folder of types/ with no plugin.json, a file there other than README.md, and two folders that name one plugin stop the sync, as that list refuses them. The manifests are committed at HEAD of a plugins checkout, which that repository's own check keeps current. The script fetches origin and stops unless the checkout is at origin/main, or, with MARFA_PLUGINS_TAG, at that tag's commit. Run it after scripts/sync-from-marfa.sh (the headers link the types the shipped catalog has).
  • The script writes src/generated/connectors/: connectors.json, the list the docs hold, derived from the manifests (a connector's name, title, description, source, mark, types and the types it carries back: a kind with the direction out or both), source.json (the plugins commit, and the tag if one names it), the connector index and one header for each connector. It also writes src/generated/plugins/: families.json (each family's types, status words, guidance and display hints, as the plugin declares them), one header per family and index.md, every plugin the repository publishes. A row is a connector, a type family or both, and the list gives no count. A family's header shows its version, the release tag on the commit without the leading v, and no version line when no tag names the commit. Each connector page includes its header; a family page includes its header. The Plugins page (content/docs/catalog/connectors/index.mdx) includes src/generated/plugins/index.md. The connector index stays generated, and that page does not include it, because the plugin list already names each connector. It also writes a page for a connector or a family that has none, holding only its header, with a description and a job line written from the title (and, for a connector, the source name) so they fit the page limits. A header says what a connector can carry back, which is its widest direction; no manifest says which setting turns that off, so the header does not. A page that exists is never overwritten. Neither folder's meta.json is touched. The connectors folder lists no pages, so the sidebar orders those pages by file name.
  • scripts/sync-from-marfa.sh runs --relink at its end whenever the docs hold a copy of the list, because a type links to its Catalog page only if the shipped catalog has one: a catalog change then moves the links with no second command.
  • A page under content/docs/catalog/connectors/ must have a connector of the same name: remarkIcons fails the build for one that has none, and src/lib/connectors.test.ts checks both ways.
  • After changing the script, run .github/scripts/sync-from-plugins.test.sh.

The changelog

node --experimental-strip-types scripts/sync-changelog.ts   # GITHUB_TOKEN is used when set
  • The Changelog page is built from the GitHub release notes of withmarfa/marfa, never written by hand. The script reads the published releases and writes src/generated/changelog.json, newest first, from FIRST_VERSION in the script (earlier releases were written in an older shape and stay on GitHub). It skips drafts and pre-releases.
  • Run it after each Marfa release's notes are written, and open a pull request with the file. The release notes have a fixed shape, which src/lib/changelog.ts reads: a summary, an optional **Breaking:** paragraph, a ### section for each part (Server, CLI, Core, TypeScript SDK, Swift SDK) and a **Full changelog:** link. Fix a wrong note on the release in GitHub and run the script again.
  • source.config.ts writes the same releases into the page's Markdown copy and, through remarkChangelogIndex, into its search index.

Docs pass at each release

After each Marfa release, one docs agent works the open docs issues and rewrites each page they name whole, to STYLE.md. Nobody else edits a page for a code change. The staleness report is the backstop: it finds the pages that cite something a release changed and that no issue named. It names pages to read again, never asks for a change, and "no change needed" is a normal answer.

  1. If no docs commit has synced the new release tag, run the sync and merge its pull request first. Run the changelog sync once the release's notes are written. Run the connectors sync once withmarfa/plugins has followed the release (source.json says which commit the docs hold), and merge its pull request: the marfa sync only relinks the headers it already has.

  2. Work the open docs issues. Close each when its page is right.

  3. Find the commits that synced the previous release and the new one, and run the staleness report between them:

    git log --format='%h %ad %s' --date=short -- src/generated/marfa-release.json
    git show <commit>:src/generated/marfa-release.json   # which release a commit synced
    node --experimental-strip-types scripts/staleness-report.ts <previous-release-commit> <new-release-commit>
  4. Read each page it lists that no issue covered against the contract and the API description. Rewrite a page whole if it is out of date, and leave it alone if it is right. Do the pages under "chapter changed" last.

On a pull request, the Docs reports job writes the same report to the job summary when openapi.json or src/generated/contract-index.json changed. It cannot fail the job.

CI and publishing

  • CI runs on every pull request and every push to main. Full CI (named Draft CI while the pull request is a draft) is a roll-up of Build and type-check, and with Pull request description it is a required check, so never add paths filters to ci.yml: a filtered-out run leaves the check pending. .github/scripts/ci-changes.sh skips the build only for root AGENTS.md, CLAUDE.md, README.md and LICENSE, the agent directories, .githooks/ and the GitHub templates, and runs the sync scripts' tests only when scripts/sync-from-marfa.sh, scripts/sync-from-plugins.sh, either one's test or ci.yml changed.
  • A pull request description follows the organization's template: Pull request description fails it otherwise (scripts/check-pr-description.ts).
  • A newer push cancels a pull request's earlier run; a push to main is never cancelled.
  • Every workflow runs on GitHub-hosted ubuntu-latest. The CodeQL workflow owns code scanning, so GitHub's default CodeQL setup stays off.
  • Merging to main publishes. Publish runs when CI succeeds on main. Each Worker has its own job, which deploys only when something that target builds from changed since the commit the site serves, then fails unless the site's /version.json reports the deployed commit.
  • Never build both targets and then deploy in one tree. The Cloudflare plugin writes one deploy pointer per project root and every build rewrites it, so a bare wrangler deploy deploys whichever target built last. deploy:status passes the config its own build emitted.
  • Publish has no schedule. Run it by hand with mode set to check to compare each live commit with main and check that the status store is still written, or to publish to deploy. target limits it to docs or status. Nothing reports outside GitHub: a red run is the signal.
  • Deploying uses the CLOUDFLARE_API_TOKEN secret and the CLOUDFLARE_ACCOUNT_ID variable. The analytics key is the POSTHOG_PROJECT_KEY_SITES variable, passed to the build as DOCS_POSTHOG_KEY. Never commit any of them.

Code Review Rules

Report only a problem you can show: name the page, input or step, and what goes wrong. Leave formatting, and what the content lint and CI catch, to them. content/AGENTS.md and src/AGENTS.md add rules for their areas.

  • Untrue against marfa. Flag a Marfa name, field, error code, rule or example that marfa's contract, openapi.json or code contradicts. Safe path: check it there and link the rule's heading.
  • Generated file edited. Flag a hand edit under src/generated/ or to openapi.json. Safe path: fix the source in marfa and run the sync.
  • Publishing weakened. Flag a paths filter on ci.yml, a deploy that can run where both targets were built, a self-hosted runner, or a publish job that no longer checks /version.json.
  • Worker route frozen. Flag a change to the prerender filter in vite.config.ts that freezes /version.json, /mcp or anything under /api/ as a static file.
  • Private detail committed. Flag a token, key, account ID, internal hostname or personal path in a tracked file.
  • Stale instructions. Flag a change that leaves an AGENTS.md, STYLE.md, the README or a comment untrue, and fix it in the same pull request.