moonbit-refactoring — community moonbit-refactoring, http11.mbt, community, ide skills, Claude Code, Cursor, Windsurf

v1.0.0
GitHub

About this Skill

Ideal for Rust-focused AI Agents requiring advanced code refactoring capabilities with minimal public API exposure. port from shiguredo/http11-rs

f4ah6o f4ah6o
[0]
[0]
Updated: 3/5/2026

Agent Capability Analysis

The moonbit-refactoring skill by f4ah6o is an open-source community AI agent skill for Claude Code and other IDE workflows, helping agents execute tasks with better context, repeatability, and domain-specific guidance.

Ideal Agent Persona

Ideal for Rust-focused AI Agents requiring advanced code refactoring capabilities with minimal public API exposure.

Core Value

Empowers agents to refactor Rust codebases using declarative styles, pattern matching, and view types like ArrayView, StringView, and BytesView, while preserving public contracts and minimizing incidental mutation, utilizing libraries like http11-rs.

Capabilities Granted for moonbit-refactoring

Refactoring legacy Rust codebases for improved performance
Minimizing public API surfaces for enhanced security
Implementing declarative coding styles for better maintainability

! Prerequisites & Limits

  • Requires knowledge of Rust programming language
  • Limited to refactoring existing Rust codebases
  • Needs comprehensive testing and documentation alongside refactors
Labs Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

moonbit-refactoring

Install moonbit-refactoring, an AI agent skill for AI agent workflows and automation. Works with Claude Code, Cursor, and Windsurf with one-command setup.

SKILL.md
Readonly

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 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
    1// In package B 2using @A { ... } // re-export A's APIs

    Ensure moon check passes before proceeding.

  2. Find and update all call sites:

    bash
    1moon 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
1// Before 2fn reader_next(r : Reader) -> Char? { ... } 3let ch = reader_next(r) 4 5// After 6fn Reader::next(self : Reader) -> Char? { ... } 7let ch = r.next()

Example (chaining):

mbt
1buf..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
1let 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
1// Pattern matching - annotate the value being matched 2let tree : @pkga.Tree = ... 3match tree { 4 Leaf(x) => x 5 Node(left~, x, right~) => left.sum() + x + right.sum() 6} 7 8// Nested constructors - only outer needs full path 9let x = @pkga.Tree::Node(left=Leaf(1), x=2, right=Leaf(3)) 10 11// Return type provides context 12fn make_tree() -> @pkga.Tree { 13 Node(left=Leaf(1), x=2, right=Leaf(3)) 14} 15 16// Collections - type annotation on the array 17let trees : Array[@pkga.Tree] = [Leaf(1), Node(left=Leaf(2), x=3, right=Leaf(4))]

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
1 match gen_results.get(0) { 2 Some(value) => Iter::singleton(value) 3 None => Iter::empty() 4 }

We can pattern match directly, it is more efficient and as readable:

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

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

mbt
1match items { 2 [] => () 3 [head, ..tail] => handle(head, tail) 4 [..prefix, mid, ..suffix] => handle_mid(prefix, mid, suffix) 5}
mbt
1match s { 2 "" => () 3 [.."let", ..rest] => handle_let(rest) 4 _ => () 5}

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
1test { 2 let a_int : Int = 'b' 3 if (a_int is 'a'..<'z') { () } else { () } 4 let a_u16 : UInt16 = 'b' 5 if (a_u16 is 'a'..<'z') { () } else { () } 6 let a_char : Char = 'b' 7 if (a_char is 'a'..<'z') { () } else { () } 8}

Use Nested Patterns and is

  • Use is patterns inside if/guard to keep branches concise.

Example:

mbt
1match token { 2 Some(Ident([.."@", ..rest])) if process(rest) is Some(x) => handle_at(rest) 3 Some(Ident(name)) => handle_ident(name) 4 None => () 5}

Prefer Range Loops for 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.
  • Keep functional-state for loops for algorithms that update state.

Example:

mbt
1// Before 2for i = 0; i < len; { 3 items.push(fill) 4 continue i + 1 5} 6 7// After 8for i in 0..<len { 9 items.push(fill) 10}

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
1for i = 0, acc = 0; i < xs.length(); { 2 acc = acc + xs[i] 3 i = i + 1 4} else { acc } 5where { 6 invariant: 0 <= i <= xs.length(), 7 reasoning: ( 8 #| ... rigorous explanation ... 9 #| ... 10 ) 11}

Tests and Docs

  • Prefer black-box tests in *_test.mbt or *.mbt.md.
  • Add docstring tests with mbt check for public APIs.

Example:

mbt
1///| 2/// Return the last element of a non-empty array. 3/// 4/// # Example 5/// ```mbt check 6/// test { 7/// inspect(last([1, 2, 3]), content="3") 8/// } 9/// ``` 10pub 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
1moon coverage analyze -- -f summary 2moon coverage analyze -- -f caret -F path/to/file.mbt

Moon IDE Commands

bash
1moon doc "<query>" 2moon ide outline <dir|file> 3moon ide find-references <symbol> 4moon ide peek-def <symbol> 5moon ide rename <symbol> -new-name <new_name> 6moon check 7moon test 8moon info

Use these commands for reliable refactoring.

Example: spinning off package_b from package_a.

Temporary import in package_b:

mbt
1using @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.

FAQ & Installation Steps

These questions and steps mirror the structured data on this page for better search understanding.

? Frequently Asked Questions

What is moonbit-refactoring?

Ideal for Rust-focused AI Agents requiring advanced code refactoring capabilities with minimal public API exposure. port from shiguredo/http11-rs

How do I install moonbit-refactoring?

Run the command: npx killer-skills add f4ah6o/http11.mbt/moonbit-refactoring. It works with Cursor, Windsurf, VS Code, Claude Code, and 19+ other IDEs.

What are the use cases for moonbit-refactoring?

Key use cases include: Refactoring legacy Rust codebases for improved performance, Minimizing public API surfaces for enhanced security, Implementing declarative coding styles for better maintainability.

Which IDEs are compatible with moonbit-refactoring?

This skill is compatible with Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer. Use the Killer-Skills CLI for universal one-command installation.

Are there any limitations for moonbit-refactoring?

Requires knowledge of Rust programming language. Limited to refactoring existing Rust codebases. Needs comprehensive testing and documentation alongside refactors.

How To Install

  1. 1. Open your terminal

    Open the terminal or command line in your project directory.

  2. 2. Run the install command

    Run: npx killer-skills add f4ah6o/http11.mbt/moonbit-refactoring. The CLI will automatically detect your IDE or AI agent and configure the skill.

  3. 3. Start using the skill

    The skill is now active. Your AI agent can use moonbit-refactoring immediately in the current project.

Related Skills

Looking for an alternative to moonbit-refactoring or another community skill for your workflow? Explore these related open-source skills.

View All

widget-generator

Logo of f
f

f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source — self-host for your organization with complete privacy.

149.6k
0
AI

flags

Logo of vercel
vercel

flags is a Next.js feature management skill that enables developers to efficiently add or modify framework feature flags, streamlining React application development.

138.4k
0
Browser

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
AI

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
AI