|
| 1 | +# AI Coding Agent Guidelines for MoonBit Core |
| 2 | + |
| 3 | +Welcome to the MoonBit Core repository! This document provides essential guidelines for AI coding agents to be productive and effective contributors to this codebase. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | +MoonBit Core is the standard library for the MoonBit language. It is organized into modular packages, each with its own directory. Key files include: |
| 7 | +- `moon.pkg.json`: Defines package dependencies. |
| 8 | +- `.mbti` files: Generated interfaces for packages, providing a formal description of their public API. |
| 9 | +- `.mbt` files: Core implementation files, organized in block style with `///|` separators. |
| 10 | +- `_test.mbt` and `_wbtest.mbt`: Blackbox and whitebox test files, respectively. |
| 11 | + |
| 12 | +The top-level `moon.mod.json` file contains metadata about the entire module. |
| 13 | + |
| 14 | +## Key Workflows |
| 15 | +1. **Code Formatting and Interface Updates**: |
| 16 | + - Use `moon fmt` to format code. |
| 17 | + - Run `moon info` to update `.mbti` files. If no changes occur, your modifications are safe for external users. |
| 18 | + |
| 19 | +2. **Testing**: |
| 20 | + - Run `moon test` to execute tests. |
| 21 | + - Use `moon test --update` to update snapshots when behavior changes. |
| 22 | + - Analyze test coverage with `moon coverage analyze > uncovered.log`. |
| 23 | + |
| 24 | +3. **Linting**: |
| 25 | + - Use `moon check` to ensure code adheres to linting rules. |
| 26 | + |
| 27 | +## Project-Specific Conventions |
| 28 | +- **Block Style Organization**: Code blocks are separated by `///|`. The order of blocks is irrelevant, allowing independent processing. |
| 29 | +- **Deprecated Code**: Place deprecated blocks in `deprecated.mbt` files within the respective directory. |
| 30 | +- **Testing Practices**: Prefer `inspect` for snapshot testing. Use `assert_eq` sparingly, such as in loops with variable snapshots. |
| 31 | + |
| 32 | +## Integration Points |
| 33 | +- **External Dependencies**: Defined per package in `moon.pkg.json`. |
| 34 | +- **Cross-Component Communication**: Interfaces are formalized in `.mbti` files, ensuring clear boundaries between packages. |
| 35 | + |
| 36 | +## Examples |
| 37 | +- **Adding a New Function**: |
| 38 | + 1. Implement the function in a `.mbt` file, using `///|` to separate blocks. |
| 39 | + 2. Update the corresponding `.mbti` file with `moon info`. |
| 40 | + 3. Write tests in `_test.mbt` or `_wbtest.mbt`. |
| 41 | + 4. Format and lint the code with `moon fmt` and `moon check`. |
| 42 | + |
| 43 | +- **Refactoring**: |
| 44 | + 1. Modify code block by block. |
| 45 | + 2. Ensure no unexpected changes in `.mbti` files after running `moon info`. |
| 46 | + 3. Verify tests pass and update snapshots if needed. |
| 47 | + |
| 48 | +## Additional Notes |
| 49 | +- Refer to `AGENTS.md` for more detailed refactoring tips. |
| 50 | +- Use `agent-todo.md` for small, AI-friendly tasks. |
| 51 | + |
| 52 | +By following these guidelines, AI agents can contribute effectively to the MoonBit Core project. If any section is unclear or incomplete, please provide feedback for improvement! |
0 commit comments