claude/skills/moonbit-practice/SKILL.md
MoonBit code generation best practices. Use when writing MoonBit code to avoid common AI mistakes with syntax, tests, and benchmarks.
npx skillsauth add kazuph/dotfiles moonbit-practiceInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Best practices for AI when generating MoonBit code.
If you don't understand something here, use moonbit-docs skill to search the official documentation.
In MoonBit projects, prefer moon ide commands over Read tool or grep.
# ❌ Avoid: Reading files directly
Read src/parser.mbt
# ✅ Recommended: Find definitions from symbols
moon ide peek-def Parser::parse
moon ide goto-definition -tags 'pub fn' -query 'parse'
# ❌ Avoid: Searching with grep
grep -r "fn parse" .
# ✅ Recommended: Semantic search
moon ide find-references parse
moon ide outline src/parser.mbt
Why:
moon ide provides semantic search (distinguishes definitions from call sites)moon doc quickly reveals APIsmoon.pkg over moon.pkg.json - Use NEW_MOON_PKG=1 moon fmt to convertmoon doc '<Type>' to explore APIs before implementingmut is only for reassignment, not field mutation - Array push doesn't need itreturn is unnecessary - last expression is the return valueType:: prefix++ -- not supported - use i = i + 1 or i += 1try needed for error propagation - automatic (unlike Swift)await keyword - just declare with async fnfor i in 0..<n {...}function_name!(...) and function_name(...)? are deprecated///| NG: fn identity[T] is old syntax
fn identity[T](val: T) -> T { val }
///| OK: Type parameter comes right after fn
fn[T] identity(val: T) -> T { val }
///|
/// NG: -> T!Error was removed
fn parse(s: String) -> Int!Error { ... }
///|
/// OK: Use raise keyword
fn parse(s: String) -> Int raise Error { ... }
Int raise is shorthand for Int raise Error.
async fn implicitly raises by default; use noraise to enforce no errors.
///|
/// NG: ! suffix was removed
assert_true!(true)
///|
/// OK
assert_true(true)
let text =
#|line 1
#|line 2
///| is a block separator. /// comments attach to the following ///| block.
///|
/// This function is foo
fn foo() -> Unit { ... }
///|
/// This function is bar
fn bar() -> Unit { ... }
Avoid consecutive ///| at the file beginning as they create separate blocks.
moon test -u auto-updates content="" in inspect(val).
test "snapshot" {
inspect([1, 2, 3], content="") // auto-filled by moon test -u
}
After running:
test "snapshot" {
inspect([1, 2, 3], content="[1, 2, 3]")
}
Available in .mbt.md files or ///| inline comments.
| Code Block | Behavior |
|------------|----------|
| ```mbt check | Checked by LSP |
| ```mbt test | Executed as test {...} |
| ```moonbit | Display only (not executed) |
Example (inline comment):
///|
/// Increment an integer by 1
/// ```mbt test
/// inspect(incr(41), content="42")
/// ```
pub fn incr(x : Int) -> Int {
x + 1
}
Run before releasing:
moon fmt # Format code
moon info # Generate type definition files
pkg.generated.mbti is auto-generated by moon info. Don't edit it directly.
moon doc StringView # StringView methods
moon doc Array # Array methods
moon doc Map # Map methods
| Topic | Command | Details |
|-------|---------|---------|
| Test | moon test | https://docs.moonbitlang.com/en/stable/language/tests |
| Update snapshots | moon test -u | Same as above |
| Filtered test | moon test --filter 'glob' | Run specific tests |
| Benchmark | moon bench | https://docs.moonbitlang.com/en/stable/language/benchmarks |
| Doc Test | moon check / moon test | https://docs.moonbitlang.com/en/stable/language/docs |
| Format | moon fmt | - |
| Generate types | moon info | - |
| Doc reference | moon doc <Type> | - |
More accurate than grep for code navigation. See reference/ide.md for details.
# Show symbol definition
moon ide peek-def Parser::read_u32_leb128
# Package outline
moon ide outline .
# Find references
moon ide find-references TranslationUnit
# Jump to type definition (with location)
moon ide peek-def Parser -loc src/parse.mbt:46:4
Prefer functional for loops whenever possible. More readable and easier to reason about.
// Functional for loop with state
for i = 0, sum = 0; i <= 10; {
continue i + 1, sum + i // Update state
} else {
sum // Value at loop exit
}
// Range for (recommended)
for i in 0..<n { ... }
for i, v in array { ... } // index and value
MoonBit uses checked errors. See reference/ffi.md for details.
///| Declare error type
suberror ParseError {
InvalidEof
InvalidChar(Char)
}
///| Declare with raise, auto-propagates
fn parse(s: String) -> Int raise ParseError {
if s.is_empty() { raise ParseError::InvalidEof }
...
}
///| Convert to Result
let result : Result[Int, ParseError] = try? parse(s)
///| Handle with try-catch
parse(s) catch {
ParseError::InvalidEof => -1
_ => 0
}
assets/ci.yaml is a GitHub Actions workflow for CI
tools
X (Twitter) API read-only CLI. Bookmarks retrieval, tweet search, engagement analytics (likes/RT aggregation), mentions, user lookup. Use when: reading X bookmarks, searching tweets, aggregating likes/retweets, checking mentions, looking up users. Triggers: bookmark, bookmarks, X search, Twitter search, likes count, RT count, engagement, tweet analytics.
testing
単体テスト方針の要約。Kiro流で使うときは本文を必ず参照・展開する。
tools
Send prompts to other AI CLIs (Codex, Claude Code) running in sibling tmux panes and receive results back. Use this skill when the user asks to send a question or task to Codex or another Claude Code instance in a tmux pane. Handles pane discovery, CLI startup if needed, prompt delivery with proper Enter timing, delivery verification, and result return via tmux send-keys.
data-ai
TAKT ピースエンジン。Agent Team を使ったマルチエージェントオーケストレーション。ピースYAMLワークフローに従ってマルチエージェントを実行する。