Speckit cleanup run

From racecraft-lab/Paddock · View interactive version

Speckit cleanup run is an AI agent skill from the GitHub repository racecraft-lab/Paddock. Post-implementation quality gate that reviews changes, fixes small issues (scout rule), creates tasks for medium issues, and generates analysis for large issues.

How to use this skill

Skill file

User Input

$ARGUMENTS

You MUST consider the user input before proceeding (if not empty).

Goal

Perform a final quality gate after implementation. Review all changes made during implementation, identify technical debt, and handle issues according to severity:

Operating Constraints

Constitution Authority: The project constitution (.specify/memory/constitution.md) is non-negotiable. Any cleanup action that would violate constitution principles is forbidden. If a fix would conflict with a MUST principle, escalate to large issue instead of fixing.

Linter Deference: For style and formatting issues, defer to the project's configured linters. Do NOT manually fix issues that linters should handle - instead, run the linter with auto-fix if available.

Preserve User Intent: If code appears intentional (e.g., commented code with explanation, disabled tests with TODO reason), do NOT auto-fix. Escalate to medium issue for user review.

Execution Steps

1. Initialize Cleanup Context

Run .specify/scripts/bash/check-prerequisites.sh --json --require-tasks --include-tasks once from repo root and parse JSON for FEATURE_DIR and AVAILABLE_DOCS. Derive absolute paths:

Abort with error if TASKS does not exist or has no completed tasks (implementation not run).

For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\''m Groot' (or double-quote if possible: "I'm Groot").

2. Load Implementation Context

Load minimal necessary context from each artifact:

From tasks.md:

From plan.md:

From spec.md:

From constitution:

3. Identify Implementation Changes

Determine which files to review using this priority order:

  1. Task-based detection (most reliable):
  1. Git-based detection (supplementary):
  1. Build the review scope:

```

REVIEW_FILES = files from completed tasks

REVIEW_DIRS = src/, tests/, and directories from plan.md structure

EXCLUDE = node_modules/, venv/, dist/, build/, *.lock files

```

4. Detect Project Tooling

Before scanning, identify available project tools:

Linters (check for config files):

Test runners:

Record available tools for use in validation steps.

5. Perform Issue Detection

Scan each file in REVIEW_FILES for issues. Use progressive disclosure - only load file contents when checking that specific file.

A. Debugging Artifacts (SMALL - auto-fixable)

Language-specific patterns to detect and remove:

| Language | Patterns |

|----------|----------|

| JS/TS | console.log, console.debug, console.info, console.warn (non-error), debugger |

| Python | print( without logging context, breakpoint(), pdb.set_trace(), import pdb |

| Java | System.out.print, e.printStackTrace() without logging |

| Go | fmt.Print used for debugging (not in main/CLI) |

| Ruby | puts for debugging, binding.pry, byebug |

| PHP | var_dump(, print_r(, dd(, dump( |

| Rust | println! used for debugging, dbg! |

B. Dead Code (SMALL - auto-fixable with caution)

Caution: Do NOT auto-remove if:

When in doubt about intent, escalate to MEDIUM (create task) rather than auto-fixing.

C. Development Remnants (SMALL/MEDIUM)

| Pattern | Severity | Action |

|---------|----------|--------|

| TODO without ticket reference | SMALL | Add ticket or remove |

| FIXME, HACK, XXX | MEDIUM | Create follow-up task |

| localhost, 127.0.0.1 in source code | SMALL | Replace with environment variable or config |

| Disabled tests without reason | MEDIUM | Create task to fix or remove |

| Hardcoded credentials/secrets | CRITICAL | STOP - alert user immediately |

| Logging user data or queries | MEDIUM | Create task to sanitize logs |

| Import from non-existent module | MEDIUM | Create task to fix or remove |

Localhost replacement pattern:

// Before (SMALL issue)
const apiUrl = 'http://localhost:3000/api';

// After (fix)
const apiUrl = process.env.API_URL || 'http://localhost:3000/api';
D. Code Quality (MEDIUM - create tasks)

These require judgment and should NOT be auto-fixed:

E. Architecture Concerns (LARGE - generate analysis)
F. Security Concerns (LARGE/CRITICAL)

| Pattern | Severity |

|---------|----------|

| SQL string concatenation | LARGE |

| Unsanitized HTML output | LARGE |

| Hardcoded secrets | CRITICAL - halt |

| Disabled auth checks | CRITICAL - halt |

| Overly permissive CORS (*) | MEDIUM |

6. Constitution Validation

For each potential fix or issue:

  1. Check if fix would violate any MUST principle
  2. Check if issue represents a constitution violation
  3. Constitution violations are automatically LARGE severity

7. Classify and Confirm Issues

Build issue inventory with severity assignment:

Severity Heuristics:

| Severity | Criteria | Action |

|----------|----------|--------|

| CRITICAL | Security vulnerability, credential exposure, auth bypass | HALT - alert user, do not proceed until fixed |

| LARGE | Architecture problem, constitution violation, security design issue | Generate analysis in tech-debt-report.md |

| MEDIUM | Code quality issue requiring design decision, multi-file change | Create follow-up task |

| SMALL | Mechanical fix, single-file, no judgment needed | Fix with confirmation |

On CRITICAL halt: After user fixes critical issues manually, they should re-run /speckit.cleanup to continue with remaining issues.

Present findings to user before proceeding:

## Cleanup Findings

### Critical Issues (BLOCKING)
[List any - must resolve before continuing]

### Small Issues (Propose to fix now)
| # | File | Issue | Proposed Fix |
|---|------|-------|--------------|
| 1 | src/api.ts:42 | console.log | Remove line |
| 2 | src/util.ts:1 | Unused import | Remove 'lodash' |

### Medium Issues (Will create tasks)
| # | File | Issue | Task Description |
|---|------|-------|------------------|
| 1 | src/service.ts | Missing error handling | Add try/catch to API calls |

### Large Issues (Will generate analysis)
| # | Scope | Issue | Impact |
|---|-------|-------|--------|
| 1 | auth/, user/ | Circular dependency | Prevents clean testing |

**Proceed with cleanup?** (yes/no/skip-small/only-report)

Wait for user confirmation before applying fixes.

8. Execute Fixes (Small Issues)

For each confirmed small issue:

  1. Check for uncommitted changes in target file:
  1. Apply fix:
  1. Validate fix:
  1. Track changes for summary (do not commit yet)

9. Run Project Validation

After all small fixes applied:

  1. Run linter (if detected in step 4):
  1. Run tests (if test runner detected):
  1. Verify no regressions:

10. Create Tasks for Medium Issues

If user confirmed, append to FEATURE_DIR/tasks.md:

---

## Tech Debt Tasks (Generated by /speckit.cleanup)

**Generated**: [ISO DATE]
**Source**: Post-implementation cleanup of [FEATURE NAME]
**Priority**: Address before next feature iteration

### Detected Issues

- [ ] TD001 [P] Add error handling to [function] in [file:line] - missing try/catch on external API call
- [ ] TD002 Extract duplicate validation logic from [file1], [file2] into shared utility
- [ ] TD003 [P] Add JSDoc documentation to public methods in [module]
- [ ] TD004 Enable or remove skipped test in [test file] - currently disabled without explanation

ID Assignment:

11. Generate Analysis for Large Issues

Create FEATURE_DIR/tech-debt-report.md:

# Tech Debt Report: [FEATURE NAME]

**Generated**: [ISO DATE]
**Feature**: [FEATURE_DIR]
**Spec Reference**: [link to spec.md]

## Executive Summary

| Severity | Count | Immediate Action Required |
|----------|-------|---------------------------|
| Critical | 0 | None (or cleanup was halted) |
| Large | X | Review and prioritize |
| Medium | X | Tasks created in tasks.md |
| Small | X | Fixed during cleanup |

## Large Issues Requiring Analysis

### [ISSUE-001] [Descriptive Title]

**Category**: [Architecture / Security / Performance / Design]
**Location**: [file:line or module scope]
**Related Spec**: [Which requirement/story this affects]
**Constitution Impact**: [Which principles apply]

#### Problem Description

[Clear explanation of what the issue is, how it was detected, and why it matters]

#### Impact if Not Addressed

- [Concrete impact 1]
- [Concrete impact 2]
- [Risk assessment]

#### Options

**Option 1: [Name] (Recommended)**
- **Approach**: [What to do]
- **Pros**: [Benefits]
- **Cons**: [Drawbacks]
- **Effort**: [T-shirt size: S/M/L/XL]
- **Risk**: [Low/Medium/High]

**Option 2: [Name]**
- **Approach**: [What to do]
- **Pros**: [Benefits]
- **Cons**: [Drawbacks]
- **Effort**: [T-shirt size]
- **Risk**: [Low/Medium/High]

**Option 3: Defer**
- **Approach**: Document and revisit later
- **Pros**: No immediate effort
- **Cons**: [Technical debt accumulation, risks]
- **Recommended deferral period**: [timeframe or trigger]

#### Recommendation

[Which option and why, with specific next steps]

---

[Repeat for each large issue]

## Cross-References

- **Specification**: FEATURE_DIR/spec.md
- **Implementation Plan**: FEATURE_DIR/plan.md
- **Tasks**: FEATURE_DIR/tasks.md (Tech Debt section)
- **Constitution**: .specify/memory/constitution.md

## Next Steps

1. Review this report with stakeholders
2. Decide on approach for each large issue
3. Create implementation tasks for approved remediations
4. Run `/speckit.implement` to address TD tasks
5. Re-run `/speckit.cleanup` to verify resolution

12. Commit Changes (with user approval)

If small fixes were applied and validation passed:

Ready to commit cleanup fixes:
- X files modified
- Y debugging artifacts removed
- Z dead code lines removed

Commit message:
"chore(cleanup): remove debugging artifacts and dead code

- Remove console.log statements from api handlers
- Remove unused imports in utils module
- [list other changes]

Generated by /speckit.cleanup"

**Commit these changes?** (yes/no/amend-message)

13. Generate Cleanup Summary

Output final report:

## Cleanup Complete

### Summary
| Category | Found | Fixed | Tasks Created | In Report |
|----------|-------|-------|---------------|-----------|
| Critical | 0 | - | - | - |
| Small | X | X | - | - |
| Medium | X | - | X | - |
| Large | X | - | - | X |

### Files Modified
- src/api/handler.ts (removed 2 console.log)
- src/utils/parser.ts (removed unused import)

### Artifacts Updated
- [x] FEATURE_DIR/tasks.md - Added Tech Debt Tasks section (X tasks)
- [x] FEATURE_DIR/tech-debt-report.md - Created with X large issues

### Validation Status
- [x] Linter: No violations
- [x] Tests: All passing (X tests)
- [x] Constitution: No violations

### Recommended Next Steps
1. Review tech-debt-report.md for large issues
2. Run `/speckit.implement` to address TD tasks when ready
3. Consider running `/speckit.analyze` to verify overall consistency

Operating Principles

Scout Rule

"Always leave the code cleaner than you found it." Small issues are fixed immediately - but always with user visibility and confirmation.

Proportional Response

Match effort to issue severity:

Non-Destructive by Default

Constitution Compliance

Every cleanup action must respect constitution principles. When in conflict, constitution wins - escalate to large issue rather than violating principles.

Traceability

All outputs stay in FEATURE_DIR:

Idempotency

Safe to run multiple times:

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.