Imported from mizchi/crater (
AGENTS.md). Install upstream withnpx skills add mizchi/crater. Copyright stays with the author.
Project Agents.md Guide
This is a MoonBit project.
Project Structure
-
MoonBit packages are organized per directory, for each directory, there is a
moon.pkg.jsonfile listing its dependencies. Each package has its files and blackbox test files (common, ending in_test.mbt) and whitebox test files (ending in_wbtest.mbt). -
In the toplevel directory, this is a
moon.mod.jsonfile listing about the module and some meta information.
Coding convention
-
MoonBit code is organized in block style, each block is separated by
///|, the order of each block is irrelevant. In some refactorings, you can process block by block independently. -
Try to keep deprecated blocks in file called
deprecated.mbtin each directory.
Tooling
-
moon fmtis used to format your code properly. -
moon infois used to update the generated interface of the package, each package has a generated interface file.mbti, it is a brief formal description of the package. If nothing in.mbtichanges, this means your change does not bring the visible changes to the external package users, it is typically a safe refactoring. -
In the last step, run
moon info && moon fmtto update the interface and format the code. Check the diffs of.mbtifile to see if the changes are expected. -
Run
moon testto check the test is passed. MoonBit supports snapshot testing, so when your changes indeed change the behavior of the code, you should runmoon test --updateto update the snapshot. -
You can run
moon checkto check the code is linted correctly. -
When writing tests, you are encouraged to use
inspectand runmoon test --updateto update the snapshots, only use assertions likeassert_eqwhen you are in some loops where each snapshot may vary. You can usemoon coverage analyze > uncovered.logto see which parts of your code are not covered by tests.
Test System
WPT (Web Platform Tests)
Browser compatibility tests using actual WPT test files from web-platform-tests.
Location:
- Test files:
wpt-tests/css-flexbox/(HTML format) - Tools:
scripts/fetch-wpt.ts,scripts/wpt-runner.ts
Commands:
# Fetch WPT tests (from GitHub)
npm run wpt:fetch -- css-flexbox
npm run wpt:fetch -- css-flexbox --limit 50
npm run wpt:fetch -- --all
npm run wpt:fetch -- --list # Show available modules
# Run WPT comparison tests (requires Puppeteer)
npm run wpt -- wpt-tests/css-flexbox/align-content-horiz-001a.html
npm run wpt -- wpt-tests/css-flexbox/*.html
How it works:
- Fetches HTML tests from WPT repository
- Inlines external CSS, removes test scripts
- Renders in Puppeteer (browser) and Crater
- Compares layout trees (position, size)
- Reports mismatches with tolerance
Available CSS modules:
css-flexbox- Flexbox testscss-display,css-box,css-sizingcss-align,css-position,css-overflow
WPT DOM Tests
DOM API compatibility tests using WPT testharness.js.
Location:
- Test files:
wpt/dom/nodes/(HTML format, from WPT submodule) - Runner:
scripts/wpt-dom-runner.ts
Commands:
# Run all WPT DOM tests
just wpt-dom-all
# Run specific test
just wpt-dom wpt/dom/nodes/Document-createElement.html
# Run tests matching pattern
just wpt-dom "Document-*"
WebDriver BiDi Tests (Planned)
WebDriver BiDi protocol compliance tests for Playwright integration.
Location:
- Test files:
wpt/webdriver/tests/bidi/(planned) - Runner:
scripts/wpt-webdriver-runner.ts(planned)
Quality Contracts (pkspec)
specs/crater.pkl is the master quality contract for Crater. TODO.md is a navigation index into it. Open GitHub issues are the bug / fix tracker, and link back to a scenario.
Workflow when you add work
- Survey current state —
pkspec spec --goals specs/crater.pkl specs/tasks.Test.pkllists per-goal coverage;pkspec spec --nextranks unimplemented scenarios by priority. - Add a new scenario — append to
specs/crater.pklwithreviewStatus = "draft"and link the source indescription(See GitHub issue #N/Source: TODO Now (P0)). Draft scenarios don't require an implementing test, sospec-checkstays green. - Approve a scenario — when an implementing test lands, add
specRef { "scenario.id" }to a test inspecs/tasks.Test.pkl, then flipreviewStatus = "approved".pkf run spec-checkvalidates the link. - Sync
TODO.md— when a scenario is reified or approved, remove or move the matching row. Don't letTODO.mdand the scenarios drift.
Goals (priority order)
goal.local-gates(90) — pkfire task discoverabilitygoal.spec-contracts(80) — pkspec coverage is mechanically checkedgoal.css-compat(75) — per-module WPT CSS baselinesgoal.dom-compat(70) — DOM / Shadow DOM / Web Components surfacegoal.protocol-compat(65) — WebDriver BiDi / Playwright / CDPgoal.paint-accuracy(60) — Luna VRT / WPT VRT / paint fixturesgoal.diagnostic-api(55, draft) — paint tree diff / computed style / selector-scoped renderinggoal.ci-efficiency(50) — affected gating / cache hit / shard wall timegoal.release-safety(40) — workspace publish order
Commands
pkf run spec-check # approved scenarios are linked
pkf run spec-lint # Goal / Scenario references
pkf run spec-test # executable wiring smoke tests
pkspec spec --goals specs/crater.pkl specs/tasks.Test.pkl # per-goal coverage summary
pkspec spec --next specs/crater.pkl specs/tasks.Test.pkl # next-action ranking
Reify rule of thumb
- Module-level WPT residual → reuse the existing
compat.css-*-baselinescenario. File a separatebug.*scenario only when the residual outlasts the baseline rollout. - New API surface (BiDi commands, CLI flags, JS exports) →
diagnostic.*orprotocol.*scenario. - Multi-PR workstream → file a scenario from day one so each PR has a backlink in its description.
- One-shot operational tweak (refactor, changelog template, dep bump) → leave in the "Not reified" section of
TODO.md. Don't pollute pkspec with single-touch chores.
Scenario name constraint
Scenario name must match ^[a-zA-Z0-9_][a-zA-Z0-9_:.\-/ ]*$ — no +, (, ), etc. Use plain prose (flexbox min_width with justify-content centers correctly).
Project Goals
Milestone 1: Preact Compatibility
Ensure Preact can run on Crater's DOM implementation:
- Complete DOM API coverage for Preact's requirements
- Event handling (click, input, change, etc.)
- Component lifecycle support
- Virtual DOM reconciliation compatibility
Validation:
just test-preact- Run Preact test suite against Crater
Milestone 2: Playwright Integration
Enable browser automation via WebDriver BiDi:
- Implement WebDriver BiDi protocol binding
- Support core Playwright operations (navigation, clicks, inputs)
- Pass WebDriver BiDi WPT tests
Validation:
just wpt-webdriver-all- Run WebDriver BiDi WPT testsjust test-playwright- Run Playwright E2E tests against Crater