Skip to content
OpenSmartRoute
Skillv1.0.0

code-simplifier

Review RTK Rust code for idiomatic simplification. Detects over-engineering, unnecessary allocations, verbose patterns. Applies Rust idioms without changing behavior.

by rtk-ai(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from rtk-ai/rtk (.claude/skills/code-simplifier/SKILL.md) via skills.sh. Install upstream with npx skills add rtk-ai/rtk --skill code-simplifier. Copyright stays with the author.

RTK Code Simplifier

Review and simplify Rust code in RTK while respecting the project's constraints.

Constraints (never simplify away)

  • LazyLock regex — cannot be moved inside functions even if "simpler"
  • .context() on every ? — verbose but mandatory
  • Fallback to raw command — never remove even if it looks like dead code
  • Exit code propagation — never simplify to Ok(())
  • #[cfg(test)] mod tests — never remove test modules

Simplification Patterns

1. Iterator chains over manual loops

// ❌ Verbose
let mut result = Vec::new();
for line in input.lines() {
    let trimmed = line.trim();
    if !trimmed.is_empty() && trimmed.starts_with("error") {
        result.push(trimmed.to_string());
    }
}

// ✅ Idiomatic
let result: Vec<String> = input.lines()
    .map(|l| l.trim())
    .filter(|l| !l.is_empty() && l.starts_with("error"))
    .map(str::to_string)
    .collect();

2. String building

// ❌ Verbose push loop
let mut out = String::new();
for (i, line) in lines.iter().enumerate() {
    out.push_str(line);
    if i < lines.len() - 1 {
        out.push('\n');
    }
}

// ✅ join
let out = lines.join("\n");

3. Option/Result chaining

// ❌ Nested match
let result = match maybe_value {
    Some(v) => match transform(v) {
        Ok(r) => r,
        Err(_) => default,
    },
    None => default,
};

// ✅ Chained
let result = maybe_value
    .and_then(|v| transform(v).ok())
    .unwrap_or(default);

4. Struct destructuring

// ❌ Repeated field access
fn process(args: &MyArgs) -> String {
    format!("{} {}", args.command, args.subcommand)
}

// ✅ Destructure
fn process(&MyArgs { ref command, ref subcommand, .. }: &MyArgs) -> String {
    format!("{} {}", command, subcommand)
}

5. Early returns over nesting

// ❌ Deeply nested
fn filter(input: &str) -> Option<String> {
    if !input.is_empty() {
        if let Some(line) = input.lines().next() {
            if line.starts_with("error") {
                return Some(line.to_string());
            }
        }
    }
    None
}

// ✅ Early return
fn filter(input: &str) -> Option<String> {
    if input.is_empty() { return None; }
    let line = input.lines().next()?;
    if !line.starts_with("error") { return None; }
    Some(line.to_string())
}

6. Avoid redundant clones

// ❌ Unnecessary clone
fn filter_output(input: &str) -> String {
    let s = input.to_string();  // Pointless clone
    s.lines().filter(|l| !l.is_empty()).collect::<Vec<_>>().join("\n")
}

// ✅ Work with &str
fn filter_output(input: &str) -> String {
    input.lines().filter(|l| !l.is_empty()).collect::<Vec<_>>().join("\n")
}

7. Use if let for single-variant match

// ❌ Full match for one variant
match output {
    Ok(s) => process(&s),
    Err(_) => {},
}

// ✅ if let (but still handle errors in RTK — don't silently drop)
if let Ok(s) = output {
    process(&s);
}
// Note: in RTK filters, always handle Err with eprintln! + fallback

RTK-Specific Checks

Run these after simplification:

# Verify no regressions
cargo fmt --all && cargo clippy --all-targets && cargo test

# Verify no new regex in functions
grep -n "Regex::new" src/<file>.rs
# Fixed, reused patterns should be in `LazyLock<Regex>` statics

# Verify no new unwrap in production
grep -n "\.unwrap()" src/<file>.rs
# Should only appear inside #[cfg(test)] blocks

What NOT to Simplify

  • static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(...).unwrap()); — the .unwrap() here is acceptable, it's init-time
  • .context("description")? chains — verbose but required
  • The fallback match arm Err(e) => { eprintln!(...); raw_output } — looks redundant but is the safety net
  • std::process::exit(code) at end of run() — looks like it could be Ok(())but it isn't

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/rtk-ai-rtk-code-simplifier/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

rtk-ai-rtk-code-simplifier.ocm.jsonjson
{
  "ocm": "1",
  "id": "rtk-ai-rtk-code-simplifier",
  "kind": "skill",
  "name": "code-simplifier",
  "description": "Review RTK Rust code for idiomatic simplification. Detects over-engineering, unnecessary allocations, verbose patterns. Applies Rust idioms without changing behavior.",
  "publisher": "rtk-ai",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "rust",
      "simplify",
      "refactor",
      "idioms",
      "rtk",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Review RTK Rust code for idiomatic simplification. Detects over-engineering, unnecessary allocations, verbose patterns. Applies Rust idioms without changing behavior."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/rtk-ai/rtk",
      "path": ".claude/skills/code-simplifier/SKILL.md",
      "ref": "HEAD",
      "url": "https://www.skills.sh/rtk-ai/rtk/code-simplifier",
      "key": "rtk-ai/rtk/.claude/skills/code-simplifier/SKILL.md"
    },
    "allowed_tools": [
      "Read",
      "Grep",
      "Glob",
      "Edit"
    ]
  },
  "instructions": "# RTK Code Simplifier\n\nReview and simplify Rust code in RTK while respecting the project's constraints.\n\n## Constraints (never simplify away)\n\n- `LazyLock` regex — cannot be moved inside functions even if \"simpler\"\n- `.context()` on every `?` — verbose but mandatory\n- Fallback to raw command — never remove even if it looks like dead code\n- Exit code propagation — never simplify to `Ok(())`\n- `#[cfg(test)] mod tests` — never remove test modules\n\n## Simplification Patterns\n\n### 1. Iterator chains over manual loops\n\n```rust\n// ❌ Verbose\nlet mut result = Vec::new();\nfor line in input.lines() {\n   ",
  "cost": {
    "context_tokens": 963
  }
}

Fetch it by URL: GET /api/v1/registry/rtk-ai-rtk-code-simplifier/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.