Agent skill

Moonbit Refactoring

by golemcloud in golemcloud/golem

Refactor MoonBit code to be idiomatic: shrink public APIs, convert functions to methods, use pattern matching with views, add loop invariants, and ensure test coverage without regressions.

MITAuto-check passedDevelopment

Install Moonbit Refactoring

skills CLI
$ npx skills add golemcloud/golem --skill moonbit-refactoring -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install golemcloud/golem moonbit-refactoring --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/golemcloud/golem.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/moonbit-refactoring .claude/skills/moonbit-refactoring && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
moonbit-refactoring
GitHub stars
1.5k
Token cost
~2.2k tokens
SKILL.md length
782 words
Files
2
Skills in repo
289
Repo updated
First seen
Licence
MIT

At a glance

Refactor MoonBit code to be idiomatic: shrink public APIs, convert functions to methods, use pattern matching with views, add loop invariants, and ensure test coverage without regressions.

  • Works in 7 steps: Architecture first: Review package… → Inventory public APIs and call sites… → Pick one refactor theme (API… → …
  • Updating MoonBit packages
  • SKILL.md covers Intent, Workflow, Improve Package Architecture and Minimize Public API and…, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Moonbit Refactoring is an agent skill from golemcloud/golem. Refactor MoonBit code to be idiomatic: shrink public APIs, convert functions to methods, use pattern matching with views, add loop invariants, and ensure test coverage without regressions. Use when updating MoonBit packages or refactoring MoonBit APIs, modules, or tests.

Its SKILL.md is about 2.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 1 other file.

It sits in Development, covering Refactoring. The repository describes itself as: Golem Cloud is the agent-native platform for building AI agents and distributed applications that never lose state, never duplicate work, and never require you to build… The licence is MIT.

When your agent uses it

  • Updating MoonBit packages
  • Refactoring MoonBit APIs

Example prompts

  • “/moonbit-refactoring”

Workflow steps

7 steps, taken from the first numbered list in SKILL.md.

  1. Architecture first: Review package structure, dependencies, and API boundaries.
  2. Inventory public APIs and call sites (moon ide doc, moon ide find-references).
  3. Pick one refactor theme (API minimization, package splits, pattern matching, loop style).
  4. Apply the smallest safe change.
  5. Update docs/tests in the same patch.
  6. Run moon check, then moon test.
  7. Use coverage to target missing branches.

What it can do on your machine

Read from SKILL.md and the folder at commit c6a3029. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are mbt and bash).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Moonbit Refactoring loads about 2.2k tokens when it runs. Until then it costs about 73 tokens; SKILL.md has 782 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~73
When it runs · the whole SKILL.md, loaded when a task matches
~2.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from golemcloud/golem at commit c6a3029, republished under its MIT licence (© golemcloud). 782 words, ~2,238 tokens.

Download SKILL.mdSave it as .claude/skills/moonbit-refactoring/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
moonbit-refactoring
description
Refactor MoonBit code to be idiomatic: shrink public APIs, convert functions to methods, use pattern matching with views, add loop invariants, and ensure test coverage without regressions. Use when updating MoonBit packages or refactoring MoonBit APIs, modules, or tests.

MoonBit Refactoring Skill

Intent

  • Preserve behavior and public contracts unless explicitly changed.
  • Minimize the public API to what callers require.
  • Prefer declarative style and pattern matching over incidental mutation.
  • Use view types (ArrayView/StringView/BytesView) to avoid copies.
  • Add tests and docs alongside refactors.

Workflow

Start broad, then refine locally:

  1. Architecture first: Review package structure, dependencies, and API boundaries.
  2. Inventory public APIs and call sites (moon ide doc, moon ide find-references).
  3. Pick one refactor theme (API minimization, package splits, pattern matching, loop style).
  4. Apply the smallest safe change.
  5. Update docs/tests in the same patch.
  6. Run moon check, then moon test.
  7. Use coverage to target missing branches.

Avoid local cleanups (renaming, pattern matching) until the high-level structure is sound.

Improve Package Architecture

  • Keep packages focused: aim for <10k lines per package.
  • Keep files manageable: aim for <2k lines per file.
  • Keep functions focused: aim for <200 lines per function.
Splitting Files

Treat files in MoonBit as organizational units; move code freely within a package as long as each file stays focused on one concept.

Splitting Packages

When spinning off package A into A and B:

  1. Create the new package and re-export temporarily:

    mbt
    // In package B
    using @A { ... }  // re-export A's APIs

    Ensure moon check passes before proceeding.

  2. Find and update all call sites:

    bash
    moon ide find-references <symbol>

    Replace bare f with @B.f.

  3. Remove the use statement once all call sites are updated.

  4. Audit and remove newly-unused pub APIs from both packages.

Guidelines
  • Prefer acyclic dependencies: lower-level packages should not import higher-level ones.
  • Only expose what downstream packages actually need.
  • Consider an internal/ package for helpers that shouldn't leak.

Minimize Public API and Modularize

  • Remove pub from helpers; keep only required exports.
  • Move helpers into internal/ packages to block external imports.
  • Split large files by feature; files do not define modules in MoonBit.

Local refactoring

Convert Free Functions to Methods + Chaining
  • Move behavior onto the owning type for discoverability.
  • Use .. for fluent, mutating chains when it reads clearly.

Example:

mbt
// Before
fn reader_next(r : Reader) -> Char? { ... }
let ch = reader_next(r)

// After
#as_free_fn(reader_next, deprecated="Use Reader::next instead")
fn Reader::next(self : Reader) -> Char? { ... }
let ch = r.next()

To make the transition smooth, place #as_free_fn(old_name, ...) on the method; it emits a deprecated free function old_name that forwards to the method. Then you can check call sites and update them gradually by looking at warnings. Example (chaining):

mbt
buf..write_string("#\\")..write_char(ch)
Prefer Explicit Qualification
  • Use @pkg.fn instead of using when clarity matters.
  • Keep call sites explicit during wide refactors.

Example:

mbt
let n = @parser.parse_number(token)
Simplify Enum Constructors When Type Is Known

When the expected type is known from context, you can omit the full package path for enum constructors:

  • Pattern matching: Annotate the matched value; constructors need no path.
  • Nested constructors: Only the outermost needs the full path.
  • Return values: The return type provides context for constructors in the body.
  • Collections: Type-annotate the collection; elements inherit the type.

Examples:

mbt
// Pattern matching - annotate the value being matched
let tree : @pkga.Tree = ...
match tree {
  Leaf(x) => x
  Node(left~, x, right~) => left.sum() + x + right.sum()
}

// Nested constructors - only outer needs full path
let x = @pkga.Tree::Node(left=Leaf(1), x=2, right=Leaf(3))

// Return type provides context
fn make_tree() -> @pkga.Tree {
  Node(left=Leaf(1), x=2, right=Leaf(3))
}

// Collections - type annotation on the array
let trees : Array[@pkga.Tree] = [Leaf(1), Node(left=Leaf(2), x=3, right=Leaf(4))]
Show full SKILL.md (337 more words)Show less
Pattern Matching and Views
  • Pattern match arrays directly; the compiler inserts ArrayView implicitly.
  • Use .. in the middle to match prefix and suffix at once.
  • Pattern match strings directly; avoid converting to Array[Char].
  • String/StringView indexing yields UInt16 code units. Use for ch in s for Unicode-aware iteration.
We Prefer Pattern Matching Over Small Functions

For example,

mbt
 match gen_results.get(0) {
   Some(value) => Iter::singleton(value)
   None => Iter::empty()
 }

We can pattern match directly; it is often clearer and equally readable:

mbt
 match gen_results {
   [value, ..] => Iter::singleton(value)
   [] => Iter::empty()
 }

MoonBit pattern matching is pretty expressive, here are some more examples:

mbt
match items {
  [] => ()
  [head, ..tail] => handle(head, tail)
  [..prefix, mid, ..suffix] => handle_mid(prefix, mid, suffix)
}
mbt
match s {
  "" => ()
  [.."let", ..rest] => handle_let(rest)
  _ => ()
}
Char literal matching

Use char literal overloading for Char, UInt16, and Int; the examples below rely on it. This is handy when matching String indexing results (UInt16) against a char range.

mbt
test {
  let a_int : Int = 'b'
  if (a_int is 'a'..<'z') { () } else { () }
  let a_u16 : UInt16 = 'b'
  if (a_u16 is 'a'..<'z') { () } else { () }
  let a_char : Char = 'b'
  if (a_char is 'a'..<'z') { () } else { () }
}
Use Nested Patterns and is
  • Use is patterns inside if/guard to keep branches concise.

Example:

mbt
match token {
  Some(Ident([.."@", ..rest])) if process(rest) is Some(x) => handle_at(rest)
  Some(Ident(name)) => handle_ident(name)
  None => ()
}
Prefer Functional Loops to Mutation When Possible
  • Use functional state update

Example:

mbt
// Before
let mut a = 1
let mut b = 2
for i = 0 {
  if i >= n {
    break
  }
  a = a + b
  b = b + a
  continue i + 1
}
mbt
for i = 0, a = 1, b = 2 {
  if i >= n {
    break a
  }
  continue i + 1, b, b + a
}
  • Functional loops also accept range loops, so they can be simplified:
mbt
for _ in 0..<n; a = 1, b = 2 {
  continue b, a + b
} nobreak {
  a
}
Prefer Range Loops to Simple Indexing
  • Use for i in start..<end { ... }, for i in start..<=end { ... }, for i in large>..small, or for i in large>=..small for simple index loops.
  • Use for x in xs {...} if xs is an iterator(e.g, Array) or for i,x in xs {...} if you also want to use the index
  • Keep functional-state for loops for algorithms that update state.

Example:

mbt
// Before
for i = 0; i < len; i = i + 1{
  items.push(fill)
}

// After
for i in 0..<len {
  items.push(fill)
}

Loop Specs (Dafny-Style Comments)

  • Add specs for functional-state loops.
  • Skip invariants for simple for x in xs loops.
  • Add TODO when a decreases clause is unclear (possible bug).

Example:

mbt
for i = 0, acc = 0; i < xs.length(); {
  acc = acc + xs[i]
  i = i + 1
} nobreak { acc }
where {
  invariant: 0 <= i <= xs.length(),
  reasoning: (
    #| ... rigorous explanation ...
    #| ...
  )
}
Tests and Docs
  • Prefer black-box tests in *_test.mbt or *.mbt.md.
  • Add docstring tests using mbt check fenced blocks for public APIs, and verify with moon check && moon test.

Example:

mbt
///|
/// Return the last element of a non-empty array.
///
/// # Example
/// ```mbt check
/// test {
///   inspect(last([1, 2, 3]), content="3")
/// }
/// ```
pub fn last(xs : Array[Int]) -> Int { ... }

Coverage-Driven Refactors

  • Use coverage to target missing branches through public APIs.
  • Prefer small, focused tests over white-box checks.

Commands:

bash
moon coverage analyze -- -f summary
moon coverage analyze -- -f caret -F path/to/file.mbt

Moon IDE Commands

bash
moon ide doc "<query>"
moon ide outline <dir|file>
moon ide find-references <symbol>
moon ide peek-def <symbol>
moon ide rename <symbol> <new_name>
moon ide analyze [path]
moon check
moon test
moon info

Use these commands for reliable refactoring.

Example: spinning off package_b from package_a.

Temporary import in package_b:

mbt
using @package_a { a, type B }

Steps:

  1. Use moon ide find-references <symbol> to find all call sites of a and B.
  2. Replace them with @package_a.a and @package_a.B.
  3. Remove the using statement and run moon check.

© golemcloud, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file in .agents/skills/moonbit-refactoring of golemcloud/golem.

  • SKILL.md
  • LICENSE

Open the folder on GitHubat commit c6a3029

Compare with similar skills

Moonbit Refactoring next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Moonbit Refactoring compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Moonbit Refactoring this skillgolemcloud/golem1.5k—~2.2kAutomated safety check: PassMIT
Guidelinesakash-network/node1.1k22 repos~577Automated safety check: PassMIT
Component Refactoringlangflow-ai/langflow156k—~3.5kAutomated safety check: PassMIT
Migrate Core Code to Submodulestinyhumansai/openhuman42k—~2.6kAutomated safety check: PassGPL-3.0
Systematic Code Refactoringluongnv89/claude-howto42k—~3kAutomated safety check: PassMIT
Codexskills-directory/skill-codex1.5k3 repos~1.8kAutomated safety check: PassMIT

Similar skills

  • Guidelines

    akash-network/node

    Behavioral guidelines to reduce common LLM coding mistakes. An agent skill from akash-network/node.

    1.1k GitHub starsUsed in 22 repos~577 tokens
    DevelopmentAuto-check passed
  • Component Refactoring

    langflow-ai/langflow

    Refactor high-complexity React components in Langflow frontend.

    156k GitHub stars~3.5k tokensUpdated today
    DevelopmentAuto-check passed
  • Migrate Core Code to Submodules

    tinyhumansai/openhuman

    Plans and carries out moving non-host-specific code and its tests from the OpenHuman core into vendored tiny submodule libraries, then releases the submodule and re-pins the host.

    42k GitHub stars~2.6k tokensUpdated today
    DevelopmentAuto-check passed
  • Systematic Code Refactoring

    luongnv89/claude-howto

    Guides refactoring in phases based on Martin Fowler's method: research, test coverage check, planning and small tested steps, with your approval at each phase.

    42k GitHub stars~3k tokensUpdated 7 days ago
    DevelopmentAuto-check passed
  • Codex

    skills-directory/skill-codex

    A skill your agent uses when the user asks to run Codex CLI (codex exec, codex resume) or references OpenAI Codex for code analysis, refactoring, or automated editing

    1.5k GitHub starsUsed in 3 repos~1.8k tokens
    DevelopmentAuto-check passed
  • Ponytail

    DavidObando/gsharp

    Forces the laziest solution that actually works, simplest, shortest, most minimal.

    565 GitHub starsUsed in 8 repos~1.7k tokens
    DevelopmentAuto-check passed

More from golemcloud/golem

All 289 skills in this repo
  • Moonbit C Binding

    golemcloud/golem

    Guide for writing MoonBit bindings to C libraries using native FFI.

    1.5k GitHub stars~3k tokensUpdated today
    Auto-check passed
  • Adding Dependencies

    golemcloud/golem

    Adding or updating crate dependencies in the Golem workspace.

    1.5k GitHub stars~1k tokensUpdated today
    Auto-check passed
  • Analysing CI Failures

    golemcloud/golem

    Analysing GitHub Actions CI failures from a run URL. An agent skill from golemcloud/golem.

    1.5k GitHub stars~862 tokensUpdated today
    Auto-check passed
  • Adds a built-in WASM plugin that is externally released and provisioned by the registry service.

    1.5k GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • DB Migration Scripts

    golemcloud/golem

    Writing database migration SQL scripts. An agent skill from golemcloud/golem.

    1.5k GitHub stars~1.5k tokensUpdated today
    Auto-check passed
  • Debugging Hanging Tests

    golemcloud/golem

    Diagnosing and fixing hanging worker executor or integration tests.

    1.5k GitHub stars~879 tokensUpdated today
    Auto-check passed

Categories

Questions about Moonbit Refactoring

What does Moonbit Refactoring do?

Refactor MoonBit code to be idiomatic: shrink public APIs, convert functions to methods, use pattern matching with views, add loop invariants, and ensure test coverage without regressions. Moonbit Refactoring is an agent skill from golemcloud/golem. Refactor MoonBit code to be idiomatic: shrink public APIs, convert functions to methods, use pattern matching with views, add loop invariants, and ensure test coverage without regressions.

When should I use Moonbit Refactoring?

Moonbit Refactoring fits situations like: updating MoonBit packages; refactoring MoonBit APIs.

How do I install Moonbit Refactoring in Claude Code?

Run `npx skills add golemcloud/golem --skill moonbit-refactoring -a claude-code`. Or copy the skill folder (.agents/skills/moonbit-refactoring in golemcloud/golem) into .claude/skills/moonbit-refactoring in your project. Claude Code loads it when a task matches its description.

How do I install Moonbit Refactoring in Codex?

Run `npx skills add golemcloud/golem --skill moonbit-refactoring -a codex`. Or copy the skill folder (.agents/skills/moonbit-refactoring in golemcloud/golem) into .agents/skills/moonbit-refactoring in your project. Codex loads it when a task matches its description.

Can I use Moonbit Refactoring in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add golemcloud/golem --skill moonbit-refactoring -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/moonbit-refactoring, .gemini/skills/moonbit-refactoring, .github/skills/moonbit-refactoring and .opencode/skills/moonbit-refactoring in your project.

What does Moonbit Refactoring need to run?

SKILL.md names no scripts, command-line tools or credentials: Moonbit Refactoring is instructions for the agent only.

Does Moonbit Refactoring access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Moonbit Refactoring safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Moonbit Refactoring use?

Moonbit Refactoring is published under the MIT licence (from the LICENSE file in the skill folder). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Moonbit Refactoring use?

About 2.2k tokens (SKILL.md is roughly 9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Moonbit Refactoring?

Skills that share tags, products or a category with Moonbit Refactoring: Guidelines (akash-network/node, 1.1k stars), Component Refactoring (langflow-ai/langflow, 156k stars), Migrate Core Code to Submodules (tinyhumansai/openhuman, 42k stars) and Systematic Code Refactoring (luongnv89/claude-howto, 42k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Moonbit Refactoring?

golemcloud (a GitHub organization) maintains it in golemcloud/golem, which has 1,507 GitHub stars. The repository holds 289 skills in this directory. The repository was last updated on October 8, 2026.

Source: golemcloud/golem on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.