Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Craftsman: Clean Code & Refactoring

    1

    Autonomous code refactoring specialist that flattens nested branching, eliminates hidden O(n²) bottlenecks, and reduces cognitive bloat with guaranteed 100% behavioral invariance.

    $9

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Craftsman: Clean Code & Refactoring

    Craftsman: Clean Code & Refactoring

    Example session with this skill installed

    Act as Craftsman. Audit src/services/subscription.ts and refactor the most convoluted function using guard clauses while preserving exact behavior.

    • Read your context and instructions
    • Compiled the craftsman

    Summary

    Refactored processUserSubscription in src/services/subscription.ts. Flattened a 5-level nested if ladder into declarative guard clauses, validated preconditions up front, and surfaced the happy path at the root level.

    Complexity Impact

    MetricBeforeAfterDelta
    Max Nesting Depth5 levels2 levels-3 levels
    Branching Points11 points6 points-5 points
    Function Lines42 lines31 lines-11 lines
    Test Suite24 passing24 passing100% Invariant
    // src/services/subscription.ts
    export function processUserSubscription(
      user: User,
      plan: PlanTier,
      paymentMethod: PaymentMethod | null,
      options?: SubscriptionOptions
    ): SubscriptionResult {
      if (!user) {
        throw new ValidationError('USER_REQUIRED');
      }
      if (!user.isActive || user.isSuspended) {
        throw new UserAccountError('USER_INACTIVE_OR_SUSPENDED');
      }
      if (plan.status !== 'active' || plan.price < 0) {
        throw new PlanError('INVALID_PLAN_TIER');
      }
      if (!paymentMethod || !paymentMethod.isValid) {
        throw new PaymentError('INVALID_PAYMENT_METHOD');
      }
      if (user.hasActivePlan && !options?.forceUpgrade) {
        throw new SubscriptionError('USER_ALREADY_SUBSCRIBED');
      }
    
      const discountRate = options?.discount || 0;
      const chargeAmount = plan.price * (1 - discountRate);
    
      const transaction = executePayment(user, chargeAmount, paymentMethod);
      if (!transaction.success) {
        throw new PaymentError('PAYMENT_FAILED', transaction.reason);
      }
    
      const sub = recordSubscription(user.id, plan.id, transaction.id);
      sendConfirmationEmail(user.email, sub.id);
    
      return { success: true, subscriptionId: sub.id };
    }
    

    🛡️ Behavioral Invariance Verification

    • Verified identical return values across valid and error boundary conditions
    • Preserved error types (ValidationError, UserAccountError, PlanError, PaymentError, SubscriptionError)
    • Preserved temporal ordering of executePayment -> recordSubscription -> sendConfirmationEmail
    • Ran native test suite: 24/24 tests passing green

    🎯 Next Steps

    • Commit the change with Conventional Commits: refactor(subscription): flatten nested validation branches using guard clauses.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Stop letting nested if/else pyramids, hidden quadratic loops, and cognitive complexity slow your engineering team down.

    Craftsman is an autonomous clean-code refactoring skill built on first principles and the Zero-Anchor philosophy. Unlike superficial linters or style formatters that just change whitespace, Craftsman restructures code architecture:

    • 🛡️ Guaranteed Behavioral Invariance: Zero breaking changes. Preserves exact return values, error types, and temporal ordering of side effects.
    • 📐 Early Exits & Guard Clauses: Flattens deeply indented conditional pyramids into readable, linear execution pipelines.
    • ⚡ Algorithmic Hotspot Detection: Detects nested loops (O(n²)+) and hidden linear lookups inside loops (.find(), .includes(), x in list), refactoring them into O(1) set/map operations.
    • 🧹 Tames Declarative Bloat: Decomposes runaway method-chaining pipelines (.map().filter().reduce().sort()) into readable, strongly typed stages.
    • 🔬 Bundled Static Analyzer: Includes analyze_complexity.py, a zero-dependency Python tool that calculates nesting depth, branching points, and cognitive friction before and after refactoring.
    • 🌐 Universal & Language-Agnostic: Works seamlessly across TypeScript, JavaScript, Python, Go, Rust, Dart, and Java.

    What's Inside the Skill:

    • SKILL.md — Actionable instructions with trigger-based detection.
    • scripts/analyze_complexity.py — Standalone AST & indentation complexity analyzer.
    • examples/ — Concrete before/after walkthroughs and standardized deliverable templates.

    Requires Python 3 for the static analyzer. Relies on existing project test suites and typecheckers for final verification.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 7 days ago

    Requires

    Python
    Git

    Permissions

    Terminal / Shell
    Read Files
    Write Files
    Listed7 days ago

    What's inside

    Frequently Asked Questions

    Craftsman is language-agnostic and works with any codebase as long as your environment has Python 3 installed to power the static analyzer. It natively inspects and refactors TypeScript, JavaScript, Python, Go, Rust, Java, C#, PHP, and Ruby, integrating seamlessly with ecosystem-specific validation tools (such as `npm`, `bun`, `cargo`, `pytest`, `go test`, and `tsc`) to guarantee 100% behavioral invariance.

    Unlike generic prompts that might suggest logic changes, Craftsman uses a deterministic AST (Abstract Syntax Tree) scanner to identify structural friction. It prioritizes functional invariance, meaning it specifically focuses on reducing cognitive load and Big-O complexity without changing how the code behaves.

    This skill requires a local Python 3 installation to run its complexity analyzer. For the best results, your project should also have an existing test suite (like pytest or jest), which the skill uses to programmatically confirm that the refactored code is behaviorally identical to the original.

    Upon purchase, you receive the full skill package including the Python-based structural analyzer, the refactoring logic modules, and the integration scripts for standard verification tools. You will also have access to all future version updates to ensure compatibility with evolving AI agent platforms.

    Craftsman is ideal for 'God functions' with deep nesting (5+ levels), legacy handlers that have become unreadable, and data-heavy scripts where inefficient loops are causing performance bottlenecks. It is designed to lower the cognitive complexity score of your code before it reaches a human reviewer.

    New in Code Quality & Review