一键导入
check-similarity-mbt
// Detect duplicate MoonBit code using AST-based similarity analysis. Use when working with .mbt files and looking for code duplication, refactoring opportunities, or enforcing code quality.
// Detect duplicate MoonBit code using AST-based similarity analysis. Use when working with .mbt files and looking for code duplication, refactoring opportunities, or enforcing code quality.
Detect duplicate Python code using AST-based similarity analysis. Use when working with .py files and looking for code duplication or refactoring opportunities.
Detect duplicate Rust code using AST-based similarity analysis. Use when working with .rs files and looking for code duplication or refactoring opportunities.
Detect duplicate code using AST-based similarity analysis. Auto-selects the right tool based on file types in the project (similarity-ts for TypeScript/JavaScript, similarity-py for Python, similarity-mbt for MoonBit, similarity-rs for Rust, etc).
Detect duplicate TypeScript/JavaScript code using AST-based similarity analysis. Use when working with .ts/.tsx/.js/.jsx files and looking for code duplication or refactoring opportunities.
| name | check-similarity-mbt |
| description | Detect duplicate MoonBit code using AST-based similarity analysis. Use when working with .mbt files and looking for code duplication, refactoring opportunities, or enforcing code quality. |
| argument-hint | [path] [--threshold 0.85] [--print] |
| allowed-tools | Bash(similarity-mbt *) Bash(cargo run -p similarity-mbt *) Read Grep Glob |
| paths | **/*.mbt |
Run similarity-mbt on the target MoonBit project to detect duplicate functions, then analyze the results and propose a refactoring plan.
If similarity-mbt is not installed:
cargo install similarity-mbt
Run with the arguments provided, or use sensible defaults:
similarity-mbt $ARGUMENTS
If no arguments are given, scan the current directory:
similarity-mbt . --threshold 0.85 --min-lines 5
Read the output and categorize duplicate pairs:
get_width vs get_height, offset_x vs offset_y): Common in layout/graphics code. Abstract with an axis parameter or generic._with_options variants (e.g. parse_rule vs parse_rule_with_diagnostics): Use optional parameters or builder pattern.For each high-priority pair, suggest a concrete refactoring:
| Option | Description |
|---|---|
--threshold <0-1> | Similarity threshold (default: 0.85) |
--min-lines <n> | Skip functions shorter than n lines (default: 3) |
--min-tokens <n> | Skip functions with fewer than n AST nodes |
--print | Show actual code snippets in output |
--filter-function <name> | Only show pairs matching function name |
--filter-function-body <text> | Only show pairs whose body contains text |
--fail-on-duplicates | Exit code 1 if duplicates found (CI use) |
--rename-cost <0-1> | APTED rename cost (default: 0.3, lower = more tolerant of renames) |
--no-size-penalty | Disable penalty for differently-sized functions |
0.95+: Nearly identical (variable renames only)0.85-0.95: Same algorithm, minor differences0.75-0.85: Similar structure, different details0.70-0.75: Related logic, worth investigating--threshold 0.9 to find obvious duplicates, then lower to 0.85--print to see actual code for top pairs--min-lines 5 to skip trivial accessors--filter-function <name> to focus on a specific functionsimilarity-mbt . --threshold 0.95 --fail-on-duplicates --min-lines 5// Before: two functions
fn get_width(self) -> Double { ... }
fn get_height(self) -> Double { ... }
// After: one function with axis parameter
fn get_dimension(self, axis : Axis) -> Double { ... }
// Before: set_attribute / remove_attribute with identical structure
// After: shared body with operation parameter or closure
fn modify_attribute(self, node, name, op : (Map[String, String], String) -> Unit) -> Result[Unit, Error] { ... }
// Before: parse_rule / parse_rule_with_diagnostics
// After: single function with optional diagnostics collector
fn parse_rule(self, diagnostics~ : Array[Diagnostic]? = None) -> Rule { ... }