Tidy

From SDiamante13/dotfiles · View interactive version

Tidy is an AI agent skill from the GitHub repository SDiamante13/dotfiles. TDD Production Code Refactoring Process. Triggers on 'tidy up', 'tidy this', 'clean up code'. Use for refactoring production code with test coverage.

How to use this skill

Skill file

TDD Production Code Refactoring Process

STARTER_CHARACTER = 🟣

NEVER make changes to Test code in this process.

This process is for refactoring production code with test coverage.

Initial Setup

  1. Locate Test File Proactively
  1. Verify Tests Pass
  1. Scan for Refactoring Opportunities

1. Dead code (commented code, unused variables)

2. Poor names (unclear variables/methods)

3. Long methods (> 25 lines)

4. Duplication (repeated code blocks)

5. Complex conditionals (nested ifs, no guard clauses)

6. Unnecessary locals (single-use variables)

7. Unused imports

Refactoring Loop

The approval is interactive and stays here (Initial Setup step 3): you present the

numbered findings, ask which to proceed with, and wait for user confirmation. Only the

deterministic apply → green-gate → commit/revert loop is encoded as a Workflow, so the

strike cap, green gate, and exact commit-message format run reliably instead of by prose.

Once the user has confirmed the subset, invoke the Workflow tool with the bundled script,

passing the human-approved refactor list (in priority order):

Workflow({
  scriptPath: "${CLAUDE_PLUGIN_ROOT}/skills/tidy/workflow.js",
  args: {
    refactors: ["<approved refactor 1>", "<approved refactor 2>", ...],  // priority order
    testCommand: "<how to run the suite>",   // optional; agent infers if omitted
    productionFile: "<path>",                 // optional; the file being tidied
    testFile: "<path>"                        // optional; NEVER modified
  }
})

For each approved refactor the workflow runs:

  1. An agent applies only that one refactoring (one at a time, in priority order) to

production code — it NEVER touches test code — and returns the diff.

  1. A gate agent (Haiku) runs the test suite and returns { passed, output }.
  2. If passed === true: commit with message format "- r <refactoring>" (quotes must

include the - r). The loop does not commit until the gate reports passed === true.

  1. If tests fail: revert this attempt's changes and retry — up to three attempts.

It returns { total, attempted, committed, halted, outcomes }, where each outcome carries

{ index, refactor, committed, commitMessage, attempts, halted }. Give a brief status

update after each refactor from the returned outcomes.

Stop conditions:

When the workflow returns halted: true, pause and check with the user before doing

anything else — report which refactor failed and its attempt output; do not continue to the

next refactor on your own.

Code Style Guidelines

Common Refactorings (in priority order)

  1. Remove dead code - commented code, unused variables
  2. Better names - rename unclear variables/methods
  3. Extract methods - break up long methods
  4. Remove duplication - DRY principle
  5. Simplify conditionals - reduce nesting, use guard clauses
  6. Remove unnecessary locals - inline single-use variables
  7. Clean imports - remove unused imports
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.