MoonBit Action Handbook
This is the fast entry point for MoonBit work.
Use this file for common tasks, then jump to skills/ or references/ only when the task needs more depth.
Start Here
Use these commands to validate the local toolchain and start a project:
moon --version
moon new my-app
moon check
moon test
moon build
moon fmt
If the user asked for a specific target, verify the target in the relevant sub-skill before choosing build flags.
Minimal Code Shapes
Function
fn greet(name: String) -> String {
"Hello, \{name}!"
}
Main
fn main {
println(greet("MoonBit"))
}
Struct and enum
struct Point {
x: Int
y: Int
}
enum Color {
Red
Green
Blue
}
Trait and impl
pub(open) trait Show {
fn to_string(self) -> String
}
impl Show for Point with to_string(self) -> String {
"Point(\{self.x}, \{self.y})"
}
Error handling
suberror NotFound
fn lookup(id: Int) -> String raise NotFound {
if id <= 0 {
raise NotFound
}
"ok"
}
Task Router
| User intent |
Go to |
Use when |
| Create a new project |
skills/1-create-project/SKILL.md |
New app, library, CLI, or template selection |
| Write or refactor code |
skills/2-write-code/SKILL.md |
Functions, traits, generics, match, visibility, mutation |
| Debug errors |
skills/3-debug-errors/SKILL.md |
Parse errors, type errors, compiler diagnostics, bad migrations |
| Write tests |
skills/4-write-tests/SKILL.md |
Test layout, assertions, test helpers, coverage |
| Optimize performance |
skills/5-optimize/SKILL.md |
Runtime speed, binary size, backend choice, benchmarking |
| Publish a library |
skills/6-publish-lib/SKILL.md |
mooncakes release, package prep, validation, versioning |
| Integrate FFI |
skills/7-ffi-integration/SKILL.md |
C/JS interop, extern bindings, wrapper design |
| Make architecture decisions |
skills/8-architecture-decisions/SKILL.md |
API shape, module boundaries, design tradeoffs |
Reference Map
| File |
Best use |
references/syntax.md |
Quick syntax lookup |
references/type-system.md |
Types, options, results, refs, and data modeling |
references/generics-traits-methods.md |
Generics, traits, methods, and implementation patterns |
references/pattern-matching.md |
Match expressions and advanced branching |
references/error-codes.md |
Compiler errors and fix strategies |
references/project-layout.md |
Module and package layout |
references/app-templates.md |
Project templates and scaffolding patterns |
references/library-design.md |
Public API and library design |
references/multi-backend.md |
Wasm, JS, and native backend strategy |
references/real-world-examples.md |
Case studies from real projects |
references/pitfalls.md |
Common mistakes and how to avoid them |
references/async.md |
Experimental async support |
references/verification.md |
Experimental verification material |
references/decision-matrices.md |
Tradeoff tables for choosing an approach |
references/architecture.md |
How this skill is organized |
Execution Checklist
Use this checklist before handing work back:
- Run
moon check.
- Run
moon test.
- Run
moon fmt.
- Build the target the user cares about.
- If the task touches public API, verify the route to
skills/8-architecture-decisions/.
Guidance
- Prefer the sub-skill when the task is focused and specific.
- Prefer
references/ when you need deeper detail or a second example.
- Avoid hard-coded claims about exact MoonBit syntax or release dates unless they are verified against the installed toolchain.
- Keep examples minimal in this file; put specialized patterns in the child skills and references.
Notes
- This skill is a router and handbook, not a full tutorial.
- If a user reports a compiler error, route to
skills/3-debug-errors/ first and then confirm with references/error-codes.md if needed.
- If a user asks for performance advice, route to
skills/5-optimize/ and measure before changing code.
- If a user asks for a new project, route to
skills/1-create-project/ and choose the template before writing code.
1---2name: moonbit3description: Use when the user asks about MoonBit project setup, writing or refactoring code, debugging compiler errors, tests, publishing, optimization, FFI, or architecture decisions. Keywords: MoonBit, .mbt, .pkg, moon new, moon build, moon test, moon check.4---56# MoonBit Action Handbook78> This is the fast entry point for MoonBit work.9>10> Use this file for common tasks, then jump to `skills/` or `references/` only when the task needs more depth.1112## Start Here1314Use these commands to validate the local toolchain and start a project:1516```bash17moon --version18moon new my-app19moon check20moon test21moon build22moon fmt23```2425If the user asked for a specific target, verify the target in the relevant sub-skill before choosing build flags.2627## Minimal Code Shapes2829### Function3031```moonbit32fn greet(name: String) -> String {33 "Hello, \{name}!"34}35```3637### Main3839```moonbit40fn main {41 println(greet("MoonBit"))42}43```4445### Struct and enum4647```moonbit48struct Point {49 x: Int50 y: Int51}5253enum Color {54 Red55 Green56 Blue57}58```5960### Trait and impl6162```moonbit63pub(open) trait Show {64 fn to_string(self) -> String65}6667impl Show for Point with to_string(self) -> String {68 "Point(\{self.x}, \{self.y})"69}70```7172### Error handling7374```moonbit75suberror NotFound7677fn lookup(id: Int) -> String raise NotFound {78 if id <= 0 {79 raise NotFound80 }81 "ok"82}83```8485## Task Router8687| User intent | Go to | Use when |88|---|---|---|89| Create a new project | `skills/1-create-project/SKILL.md` | New app, library, CLI, or template selection |90| Write or refactor code | `skills/2-write-code/SKILL.md` | Functions, traits, generics, match, visibility, mutation |91| Debug errors | `skills/3-debug-errors/SKILL.md` | Parse errors, type errors, compiler diagnostics, bad migrations |92| Write tests | `skills/4-write-tests/SKILL.md` | Test layout, assertions, test helpers, coverage |93| Optimize performance | `skills/5-optimize/SKILL.md` | Runtime speed, binary size, backend choice, benchmarking |94| Publish a library | `skills/6-publish-lib/SKILL.md` | mooncakes release, package prep, validation, versioning |95| Integrate FFI | `skills/7-ffi-integration/SKILL.md` | C/JS interop, extern bindings, wrapper design |96| Make architecture decisions | `skills/8-architecture-decisions/SKILL.md` | API shape, module boundaries, design tradeoffs |9798## Reference Map99100| File | Best use |101|---|---|102| `references/syntax.md` | Quick syntax lookup |103| `references/type-system.md` | Types, options, results, refs, and data modeling |104| `references/generics-traits-methods.md` | Generics, traits, methods, and implementation patterns |105| `references/pattern-matching.md` | Match expressions and advanced branching |106| `references/error-codes.md` | Compiler errors and fix strategies |107| `references/project-layout.md` | Module and package layout |108| `references/app-templates.md` | Project templates and scaffolding patterns |109| `references/library-design.md` | Public API and library design |110| `references/multi-backend.md` | Wasm, JS, and native backend strategy |111| `references/real-world-examples.md` | Case studies from real projects |112| `references/pitfalls.md` | Common mistakes and how to avoid them |113| `references/async.md` | Experimental async support |114| `references/verification.md` | Experimental verification material |115| `references/decision-matrices.md` | Tradeoff tables for choosing an approach |116| `references/architecture.md` | How this skill is organized |117118## Execution Checklist119120Use this checklist before handing work back:1211221. Run `moon check`.1232. Run `moon test`.1243. Run `moon fmt`.1254. Build the target the user cares about.1265. If the task touches public API, verify the route to `skills/8-architecture-decisions/`.127128## Guidance129130- Prefer the sub-skill when the task is focused and specific.131- Prefer `references/` when you need deeper detail or a second example.132- Avoid hard-coded claims about exact MoonBit syntax or release dates unless they are verified against the installed toolchain.133- Keep examples minimal in this file; put specialized patterns in the child skills and references.134135## Notes136137- This skill is a router and handbook, not a full tutorial.138- If a user reports a compiler error, route to `skills/3-debug-errors/` first and then confirm with `references/error-codes.md` if needed.139- If a user asks for performance advice, route to `skills/5-optimize/` and measure before changing code.140- If a user asks for a new project, route to `skills/1-create-project/` and choose the template before writing code.141