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
106 changes: 103 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ site/ documentation site + playground (Astro + Starlight, Gi
src/content/docs/ the pages (Markdown/MDX, JS + Python + Rust tabs on every example);
reference/spec.md is generated from spec/SPEC.md
src/components/ HeroDemo, Playground (runs js/ in the browser), Feature, Stats
src/lib/ trackview.ts (highlight + field rendering), icons.ts (Lucide SVG strings)
src/lib/ trackview.ts (highlight + field rendering), icons.ts (Lucide SVG strings),
lang.ts (one language choice for docs tabs, install switch, playground)
scripts/sync-spec.mjs copies spec/SPEC.md into the docs at build time
scripts/compare-ports.mjs every fixture through js/dist, the Python port and the Rust crate, diffs
the full outputs (parseTracklist and applyEdits included);
Expand All @@ -127,7 +128,7 @@ scripts/dump_py.py Python side of compare-ports (JSONL in, to_dict() JSON
pr-title.yml (conventional PR titles)
.github/release-notes/ optional hand-written highlights prepended to a GitHub Release
release-please-config.json, .release-please-manifest.json release automation (never hand-edit the manifest)
js/CHANGELOG.md, spec/CHANGELOG.md, python/CHANGELOG.md generated by release-please from commit messages
js/CHANGELOG.md, spec/CHANGELOG.md, python/CHANGELOG.md, rust/CHANGELOG.md generated by release-please
```

## Golden rule
Expand Down Expand Up @@ -197,7 +198,8 @@ Every port must produce byte-identical output. The full text is SPEC.md R0; in s
- **Iterate by code point** (R0.5), not UTF-16 unit or byte. No offsets in the output.
- *Digit* means ASCII `0`–`9` only.
- **Total** (R0.8): any string returns a ParsedTrack. Never throw or panic, including on bad
options. No backtracking blowups: a 10,000-code-point input finishes well under 100 ms.
options. No backtracking blowups: a 10,000-code-point input takes tens of milliseconds in JS and Rust
and well under a second in Python (the suites enforce 1 s, Rust 2 s).

## Commands

Expand Down Expand Up @@ -385,6 +387,92 @@ icons or gradients, data colours only for parsed output) are written at the top
changed pages with `pnpm docs`. Site-only commits (`docs(site)`, `fix(site)`, `feat(site)`) don't
trigger a release; changes under `js/`, `python/` or `spec/` do, even `docs:` ones.

### What the docs may and may not claim

Each of these was written wrong at least once and caught in review. Check them when you touch docs.

| Don't write | Write instead, and why |
|---|---|
| "linear time" | Hand-written scanners, no regex backtracking. The R9.2 dedup in JS and Python is quadratic on thousands of repeated `feat.` credits (Rust is near-linear). |
| "under 100 ms" for every port | True for JS (10 to 70 ms on 10,000 code points) and Rust (under 20 ms, release build). Python takes 40 to 170 ms. The suites enforce 1 s (JS, Python) and 2 s (Rust). |
| "identical output for any input" | Identical on every fixture input. The Rust crate takes NFC from `unicode-normalization` (Unicode 18), Node 24 has Unicode 17, so 32 new combining marks can be ordered differently. Link `project/ports/#what-the-rust-port-taught`. |
| "zero dependencies" for the project | Zero in JS and Python. Rust has one, `unicode-normalization`. |
| a size in mixed units | Core: about 18 kB gzip. Tracklist entry: about 8.4 KiB (8,607 B), budget 9 KiB. Re-measure with `pnpm --filter trackparse build && pnpm --filter trackparse size`. |
| every suite checks "no word goes missing" | Only `rust/tests/properties.rs` has that test today. |
| "Neuropunk" on the site | "a private corpus of real podcast tracklists". Fixture file names and `source` values keep the name; the site and READMEs don't. |

Numbers that appear in many files (grep all of them when one changes): fixture counts (13,130 =
1,203 handwritten + 11,927 generated), test counts (vitest 1,352, pytest 1,342), CI matrices
(Node 22/24 + 18/20, Python 3.9 to 3.14, Rust stable + 1.74), the 27 version types, the sizes
above. `spec/generator/README.md` links the site anchor `#generated-11927-cases`, which changes
with the count.

### Checking examples and links

- **Run every block, in every language.** A harness that extracts the fenced `js` / `python` /
`rust` blocks per file, runs them and compares each `expr // output` line takes minutes to write
and has caught every wrong output so far. JS runs against `js/dist` after a build, Python with
`uv run python`, Rust in a scratch cargo project with a path dependency (`features = ["serde"]`,
plus `serde_json`).
- **Rust blocks must compile as written, in page order.** A bare `value;` moves a non-`Copy`
value, so a later line that uses it fails (E0382, E0507). Borrow instead: `&track.artists;`,
`&list.warnings;`, `&parse(…).versions[0];`. Type listings (`pub struct …`) go in their own block,
apart from runnable code.
- **`rust/README.md` is compiled.** `lib.rs` includes it as crate docs, so every Rust block in it is
a doc test: run `cargo test --doc --all-features` after editing it.
- **Python examples need their imports** (`from trackparse import ParsedTrack`). Functions that
take a string raise `TypeError` on other input; `format_track` and `all_artists` take a
`ParsedTrack` unchecked.
- **Links.** Package READMEs use full `https://` URLs. Check site URLs against the built HTML
(`site/dist`), ids included. `curl` gets 403 from npmjs.com and 404 from crates.io pages without
`Accept: text/html`: use `registry.npmjs.org/trackparse` and `crates.io/api/v1/crates/trackparse`.
Shields badges can lag a release by some hours.
- **Renaming a heading breaks published links.** Keep the old id with an `<a id="…">` alias, as
`reference/parse.mdx` does for `serialising-to-json` and `json-and-python-objects`.
- **Spelling** in docs is American (`normalize`, `serialize`, `recognize`, `catalog`), except
"behaviour", which the spec uses throughout.

### Site internals worth knowing

- **One language choice.** `site/src/lib/lang.ts` reads and writes Starlight's own
`starlight-synced-tabs__lang` localStorage entry (the value is the tab label). The docs tabs, the
install switch (`Install.astro`) and the playground code panels all follow it. It must keep
working when storage is blocked.
- **Playground state is in the URL hash** (input, mode, options, `known`, edits), so a docs page can
link to a prefilled example. Look at an existing link before writing one.
- **Warning names link to `reference/warnings`** with a text fragment
(`#tracklist-warnings:~:text=<code>`); dashes in the code are encoded as `%2D`. The section ids
are `track-warnings`, `tracklist-warnings` and `edit-warnings`.
- **Astro 7's Markdown processor rejects rehype plugins.** Small DOM fixes are head scripts in
`astro.config.mjs` (the `nowrap` class on space-free code in tables).
- **Building somewhere else.** `astro build --outDir` into `/tmp` fails with `EXDEV` (rename across
filesystems). Build into a folder under `site/node_modules/.cache/` when `site/dist` is in use.
- `pnpm lint` covers `js/` only, and `astro check` stops at an install prompt. The build and a
browser are the checks for the site. Look at 1280 and 375 px, light and dark; a headless Chrome
over the DevTools protocol is enough.

## Working with several agents

- Give each agent its own files and say so. The split that worked for a docs pass: root README;
the package READMEs and `spec/**/README.md`; `site/src/content/docs/**`; components, `lib/`,
styles, `index.mdx` and `playground.mdx`. Then one reviewer that edits nothing, then one fixer.
- Agents never commit, push or switch branches. The session that started them commits.
- Two agents building the site at once must not share `site/dist`.
- Timings measured while other agents run are too high, and
`test_ten_thousand_lines_are_fast` in the Python suite can fail on a busy machine. Re-run it alone
before believing it.
- A reviewer should run the examples, not read them. Ask for file, line and the concrete fix.

## Known gaps (not yet fixed)

- R9.2 dedup is quadratic in JS and Python on thousands of repeated credits (Rust already fixed).
- `format(track, { feat: "nope" })` drops the featured artists in JS and Python instead of falling
back to the default, unlike other bad options. Needs a spec decision and a fixture first.
- Python tracklist types have `to_dict()` but no `from_dict()`; `ParsedTrack` has both.
- JS and Python do not test invariant 6 ("no word goes missing"); only Rust does.
- The npm and PyPI publish jobs use actions by tag; the crates.io job pins its auth action by SHA.
- The playground's Rust snippet is a whole program, the JS and Python ones are bare expressions.

## Porting guide (Rust, others)

A port is done when it passes every fixture and every invariant. The Python and Rust ports are done
Expand Down Expand Up @@ -527,6 +615,18 @@ Version rules:
`gh workflow run release.yml -f python_tag=python-vX.Y.Z` (PyPI) or
`-f rust_tag=rust-vX.Y.Z` (crates.io). The npm job always republishes from a fresh release; a
failed npm publish needs the same treatment by hand.
- **Things the 0.5.0 release taught:**
- The release PR is opened with `GITHUB_TOKEN`, so no CI runs on it and GitHub shows it as
`UNSTABLE`. That is expected; `main` was green when it was generated.
- A `docs:` commit under `js/`, `python/` or `rust/` (a package README) opens a release PR. A
commit that touches only the root README, `AGENTS.md`, `site/` or `.github/` does not.
- A component's first changelog lists every commit that ever touched its folder, because there
is no earlier tag to start from.
- crates.io refuses to publish until the account has a verified email address.
- After a release, check all three registries by API, not by badge: `registry.npmjs.org`,
`pypi.org/pypi/trackparse/json`, `crates.io/api/v1/crates/trackparse`.
- Don't force-push a PR branch to pick up `main`: GitHub's rebase-merge rebases it when there
are no conflicts.
- **Agents never merge release PRs, publish, push tags or bump versions on their own initiative.**
Merging the release PR is the maintainer's publish decision.

Expand Down
Loading
Loading