Aventuras/docs/development/modern-code.md
Tony Frazier f6a096b48f
Move the docs to decision records and check them on every push (#807)
This swaps CLAUDE.md and the hand-written docs index for a small
decision-record setup, and adds a script that checks the docs so they
stop drifting from the code.

## What changes

CLAUDE.md is gone. AGENTS.md replaces it as the one instruction file for
people and coding agents alike. It has the commands, the rules for every
change, the area-doc table, and how to record a decision. (Claude Code
only reads AGENTS.md when there's no CLAUDE.md, so it's deleted rather
than kept around as an import.)

If you use Claude Code, check one thing. It only reads AGENTS.md on
version 2.1.277 or later, and only when there's no `CLAUDE.md`,
`.claude/CLAUDE.md` or `CLAUDE.local.md` in the repo or any directory
above it. If you keep one of those, set **Project instructions** to
`claude-md-and-agents-md` in `/config` to load both. Your
`~/.claude/CLAUDE.md` doesn't count, so it's fine.

Decisions now live in `docs/decisions/`, one file each, named
`YYYY-MM-DD-slug.md`. There's one so far, the record system itself. It
sets the bar for when a choice gets an ADR at all: intent the code can't
express that spans more than one site or won't fit in a short comment.
Anything smaller stays a comment, and refining a decision amends its ADR
instead of adding a new one.

Only tagged decisions are listed in `docs/README.md`, so the index grows
with the decisions that span areas, not with every local choice. The
code leads to the local ones, either through an `ADR(slug)` comment at a
single site or through `scope`, which lists the directories an ADR
governs. For each scoped directory, `npm run docs:gen` writes the ADRs'
summaries into a generated block in that directory's `AGENTS.md`, which
Claude Code loads when it reads a file there or below. Any hand-written
text in that file is left alone. `docs/README.md`, the cross-cutting
block in AGENTS.md and the scoped blocks are all generated, so don't
edit those by hand.

Once an ADR merges, its summary is the ruling and can't change. The rest
of the record can still be refined while the summary holds. Changing the
ruling means superseding the ADR.

Raw material (logs, benchmarks, probe output) goes in `docs/evidence/`,
and an ADR has to link it. A new `.ignore` lists the folder so a keyword
search over the whole repository skips it, while a search aimed at the
folder still finds it. Agents reach evidence through the ADR's link. Two
evidence docs record how that was tested: which tools load a nested
AGENTS.md (only the Read tool does), and why no hook or instruction file
guards the folder.

`npm run docs:check` (`scripts/docs-check.ts`) checks:

- the decision files and the generated output
- `ADR(slug)` comments and scopes
- `docs/` paths named in source
- relative links in Markdown
- that evidence files are linked from a decision

It also fails if a merged ADR's summary changed or its slug disappeared,
comparing against the merge-base with `origin/master`. `--base <ref>`
picks another ref, and a ref git can't resolve is an error. The default
`origin/master` only warns when it's missing, so a clone without that
remote can still run the check. (`master` has no decisions yet, so
there's nothing to compare until this merges.) An active ADR with no
tag, no scope and no anchor draws a warning, since nothing would lead a
reader to it. Cross-cutting ADRs are exempt because AGENTS.md lists
them.

`npm run docs:gen` writes nothing while an ADR or the tag list is
invalid. Otherwise a broken record would quietly drop out of the index
and the AGENTS.md blocks.

The check runs in pre-push on every push, and with `--strict` in a new
Docs check workflow on PRs to master. That workflow fetches the full
history so the merge-base exists.

The rules that were in CLAUDE.md now have their own files under
`docs/development/`, indexed by `docs/development/README.md`.
`release.md` and `platform-support.md` are each split into the rules and
a separate evidence file. `docs/ARCHITECTURE.md` is a starting map of
the code, and `docs/architecture/network-transport.md` is new.

Every doc under `docs/architecture/` and `docs/development/` was also
checked against the current code and corrected where it had drifted.

## Smaller changes

- Markdown under `docs/` is forced to LF (`.gitattributes` and
`docs/.editorconfig`).
- Git no longer ignores AGENTS.md or `docs/evidence/`, and the ignores
for the old root-level doc files now match only at the repo root.
- tsconfig and vitest now pick up TypeScript under `scripts/`.
- The README points contributors at AGENTS.md and drops the link to the
iOS build doc.

## Needs a follow-up

`.github/CODEOWNERS` puts `docs/decisions/` under a placeholder team
(`@AventurasTeam/TODO-owning-team`). GitHub ignores an owner it can't
resolve, so it does nothing until someone fills in the real team.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01EzTd9Y26s2eHcacyqFi1QK


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Documentation**
* Added repository guidance for development rules, required checks, and
decision records; updated the README to direct contributors to the
relevant guides.
* Added checks and generated documentation for decision records, links,
evidence references, and summaries.
* Added ownership guidance for decision records and standardized
Markdown line endings in the documentation directory.
* Replaced the previous repository guide with the new contributor
guidance.

* **Chores**
* Documentation checks now run on pull requests and before pushing
changes.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 16:24:21 -05:00

3.7 KiB

Modern code

Write new code in the current idiom of the installed versions, using the newest feature each layer's floor allows. Check the installed version's docs, not memory, for what is current.

Layer Floor
JS, CSS, HTML Chrome 111 / Safari 16.4 (platform-support.md)
Svelte, Tailwind the installed 5.x and 4.x
SQL the SQLite libsqlite3-sys bundles on every platform (3.46)
Rust edition 2024

Per layer

  • Svelte: {@attach} over use: actions for new code — an attachment re-runs when state it reads changes, an action does not — and fromAction to convert an existing action unchanged. cn(…) over class: directives, snippets and callback props over slots and dispatched events.
  • HTML: the native element over a div with ARIA and key handlers — <button>, not role="button" plus tabindex and onkeydown. Where a bits-ui component exists for the job (dialog, popover, select), use it (ui-components.md).
  • TS/JS: async/await over .then chains, $state.snapshot for reactive state, structuredClone for plain values (it throws on a $state proxy) over JSON.parse(JSON.stringify(…)), toSorted/toSpliced/with/at/findLast over copy-then-mutate or index arithmetic.
  • Types: make the type system carry the shape. A known shape gets a named type, not object, Object, Record<string, …> or an index signature; a lookup is keyed by a literal union (Record<ServiceId, …>), or is a Map when its keys are truly dynamic. Derive types with keyof, typeof and indexed access rather than restating them. satisfies and discriminated unions with an exhaustive never check over casts and boolean flags; narrow unknown with a type guard at the boundary over as or any, and over Object.keys/entries cast back to the key type.
  • Tailwind: v4 names and syntax — shrink-0, grow, bg-linear-to-*, size-*, bg-(--x) — over v3 aliases and [var(--x)]. A value used twice is a token in @theme in src/app.css, not a repeated arbitrary value; tv(…) for a component with variants.
  • CSS: :has(), container queries, dvh, color-mix(), logical properties, gap — over JS measurement, vh, and margin hacks.
  • SQL: RETURNING over a follow-up SELECT or last_insert_rowid(), ->> over json_extract, ON CONFLICT … DO UPDATE over INSERT OR REPLACE (which deletes and re-inserts the row). Shipped migrations stay as they are.
  • Rust: let … else and ? over nested match/unwrap.

Some current features are still newer than the floor; the list is in platform-support.md.

Scope

This applies to code you are already changing, not to a hunt through the codebase. When you edit a function or component, modernize the dated idioms in it and in the code it directly touches, keeping its behaviour the same. Some swaps change behaviour on their own: ON CONFLICT … DO UPDATE keeps unlisted columns and the existing row, which INSERT OR REPLACE deletes and re-inserts; async turns a synchronous throw into a rejection. Make one only where it behaves the same here — every column is set, nothing depends on the delete, no caller relies on the throw — and keep the old idiom otherwise rather than adjusting other code to fit. Leave untouched files alone. Modernizations stay out of the commit message: it describes only the functional change.