agentleFS
radimsemradimsem/mithril/.claude/skills/code-simplifier/SKILL.md

code-simplifier

Skill16 starsChanged 8 months agoApache-2.0View on GitHub

Use when writing, reviewing, or editing Rust code in this project - applies iterator chains, Option/Result chaining, early returns, borrow-over-clone, and if-let simplifications per project conventions

42 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use comment-analyzer, performance and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • lin30Skill

    comment-analyzer

    微博评论抓取与深度分析,生成可视化HTML报告。Use when user asks to analyze weibo comments, analyze social media comments, or requests sentiment analysis from weibo posts

    Also in 3 projects that use this

  • pluginagentmarketplaceSkill

    performance

    Optimize application performance through caching strategies, load balancing, database scaling, and monitoring. Build systems handling thousands of concurrent users.

    Also in 3 projects that use this

  • AWSSkill

    setup-matt-pocock-skills

    Configure this repo for the engineering skills: set up its issue tracker, triage label vocabulary, and domain doc layout. Run once before first use of the other engineering skills.

    Also in 3 projects that use this

  • OpenAISkill

    verification-before-completion

    Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always

    Also in 4 projects that use this

  • AWSSkill

    to-spec

    Turn the current conversation into a spec and publish it to the project issue tracker: no interview, just synthesis of what you've already discussed.

    Also in 3 projects that use this

  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    Also in 9 projects that use this

  • +2 more from aws

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 40 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use iterator chains for transformation logic.

    line 14
  2. Very specific:

    Use match only when both arms carry logic.

    line 146

“Common” is measured: kept by at least 6 in 10 of the 40 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust Code Simplifier

Proactive pattern guide for writing simple, idiomatic Rust. Apply these patterns whenever writing or modifying Rust code — not only when asked to simplify.

Project rules: These patterns align with .claude/rules/rust-patterns.md. When in doubt, re-read the rules file.

1. Iterator Chains Over Manual Loops

Use iterator chains for transformation logic. Reserve for loops only when the body needs early error returns with ?.

// WRONG
let mut names = Vec::new();
for tool in tools {
    if tool.is_available() {
        names.push(tool.name().to_owned());
    }
}

// RIGHT
let names: Vec<String> = tools
    .iter()
    .filter(|t| t.is_available())
    .map(|t| t.name().to_owned())
    .collect();

When to keep a loop: The body calls fallible operations with ?:

// Loop is correct here — early return on error
for entry in entries {
    let meta = entry.metadata().context("failed to read metadata")?;
    process(&meta).await?;
}

2. Option/Result Chaining

Flatten nested match/if let on Option/Result into chained combinators or ?.

// WRONG — nested match pyramid
match config.project.as_ref() {
    Some(project) => match project.settings.as_ref() {
        Some(settings) => match settings.get("key") {
            Some(val) => Some(val.to_owned()),
            None => None,
        },
        None => None,
    },
    None => None,
}

// RIGHT — ? operator for Option propagation
config
    .project
    .as_ref()?
    .settings
    .as_ref()?
    .get("key")
    .map(|v| v.to_owned())

Combinator quick reference:

PatternUse when
?Propagate None/Err to caller
.map()Transform inner value
.and_then()Chain operations that return Option/Result
.unwrap_or_default()Fallback to Default impl
.unwrap_or_else(|| ...)Fallback with computation

3. Early Returns

Guard against invalid/empty states at the top. Avoid deep nesting for the main logic.

// WRONG — main logic buried in nested conditions
fn process(entries: &[Entry], prefix: &str) -> Vec<String> {
    let mut results = Vec::new();
    if !entries.is_empty() {
        if !prefix.is_empty() {
            for entry in entries {
                if entry.name.starts_with(prefix) {
                    results.push(entry.name.strip_prefix(prefix).unwrap().to_owned());
                }
            }
        }
    }
    results
}

// RIGHT — guard clauses, then flat logic
fn process(entries: &[Entry], prefix: &str) -> Vec<String> {
    if entries.is_empty() || prefix.is_empty() {
        return Vec::new();
    }

    entries
        .iter()
        .filter(|e| e.name.starts_with(prefix))
        .filter_map(|e| e.name.strip_prefix(prefix))
        .map(|s| s.to_owned())
        .collect()
}

Signals to look for: is_empty(), is_none(), is_err(), boolean flags checked before the real work begins.

4. Avoid Redundant Clones

Borrow instead of cloning. When ownership is needed, use .to_owned() (not .clone()). Use String::from("...") for string literals (not "...".to_string()).

// WRONG — clones where borrows suffice
fn format_tool(tool: &Tool) -> String {
    let data = tool.data.clone();
    let name = tool.name.clone();
    format!("{}: {}", name, data)
}

// RIGHT — format! borrows automatically
fn format_tool(tool: &Tool) -> String {
    format!("{}: {}", tool.name, tool.data)
}
// WRONG
let label = "default".to_string();
let copy = config.clone();

// RIGHT
let label = String::from("default");
let copy = config.to_owned();

5. if let for Single-Variant Match

Use match only when both arms carry logic. Use if let when only one variant matters.

// WRONG — match with throwaway arm
match result {
    Some(val) => process(val),
    None => (),
}

// RIGHT
if let Some(val) = result {
    process(val);
}

// RIGHT — match when both arms carry logic
match result {
    Ok(ctx) => tool.format(ctx).await,
    Err(e) => log_and_report(e),
}

Common Mistakes

MistakeFix
.clone() to satisfy borrow checkerRestructure to borrow, or use .to_owned() if ownership needed
"literal".to_string()String::from("literal")
Nested if/match guarding empty/noneEarly return guard clause at top
for loop that only filters + mapsIterator chain with .filter().map().collect()
match x { Some(v) => f(v), None => () }if let Some(v) = x { f(v); }
Nested match on Option chains? operator or .and_then()

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.