agentleFS
fagemxfagemx/edda/.claude/skills/regression-guard/SKILL.md

regression-guard

Skill36 starsChanged 2 months agoApache-2.0View on GitHub

Systematic scan → classify → batch fix → add automation to prevent regression

  • Reads credentials

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 5 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After fixing a class of problems, add automated prevention.

    line 89
  2. Very specific:

    Create or extend eslint.config.mjs:

    line 106
  3. Distinctive:

    Integration: Add to pre-commit (lefthook) or CI

    line 165
  4. Distinctive:

    Add to CLAUDE.md or project docs:

    line 177
  5. Distinctive:

    Run a full audit across all categories.

    line 191
  6. Distinctive:

    Run scan for each category: type-safety, error-handling, security, testing, dead-code

    line 195

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

Regression Guard — Scan, Fix, Prevent

When you fix a bug or quality issue, don't just fix it — add automated prevention so it can never happen again. This skill follows a systematic approach: scan the entire codebase for a class of problems, classify findings, batch fix, then add tooling to prevent regression.

Inspired by: vm0 e7h4n's pattern — "修了就防回歸"

Your args are: $ARGUMENTS

Parse the args:

  • scan <category> — Scan codebase for a specific problem category
  • guard <description> — After fixing something, add regression prevention
  • audit — Full audit across all categories

Categories: type-safety, error-handling, security, testing, dead-code, performance, dependencies


Operation 1: Scan

Systematically scan the codebase for a class of problems, classify by severity, produce an actionable report.

Step 1: Choose Scanning Tools

CategoryTools
type-safetybun run lint, grep "as any|@ts-ignore"
error-handlinggrep "try.*catch", grep "console.error"
securitygrep "eval|exec|innerHTML", grep "password|secret|token" in non-.env
testinggrep "\.skip|\.only", grep "setTimeout" in *.test.ts
dead-codebun run knip, grep "// TODO|// FIXME|// HACK"
performancegrep "JSON.parse.*JSON.stringify" (deep clone), grep "\.forEach" in hot paths
dependenciesnpm audit, bun run knip

Step 2: Run Scans

Execute ALL relevant scans and collect raw output:

# Example for type-safety
bun run lint 2>&1 | grep "error\|warning" > /tmp/scan-results.txt
grep -rn "as any\|@ts-ignore\|@ts-nocheck" src/ --include="*.ts" >> /tmp/scan-results.txt
wc -l /tmp/scan-results.txt

Step 3: Classify Findings

Group findings into:

## Scan Results: <category>

### P0 — Fix Now (breaks correctness or security)
| File:Line | Issue | Pattern |
|-----------|-------|---------|
| src/X.ts:42 | ... | ... |

### P1 — Fix Soon (code smell, maintainability risk)
| File:Line | Issue | Pattern |
|-----------|-------|---------|

### P2 — Nice to Have (style, minor improvement)
| File:Line | Issue | Pattern |
|-----------|-------|---------|

### Recurring Patterns
<identify the 2-3 patterns that appear most often — these are the targets for automation>

Step 4: Create Issues

For each P0/P1 group, create a batch-fix issue:

gh issue create --title "fix(<scope>): <pattern description>" --body "..."

Group by pattern, not by file. One issue per pattern, not per finding.


Operation 2: Guard

After fixing a class of problems, add automated prevention.

Step 1: Identify the Guard Type

Problem TypeGuard Mechanism
as any / unsafe typesESLint rule: @typescript-eslint/no-explicit-any (already have)
Specific anti-patternCustom ESLint rule (new plugin)
Missing validationTest case that fails without validation
Architecture violationImport restriction (ESLint no-restricted-imports)
Security issueGrep-based CI check
Dead codeKnip in pre-commit

Step 2: Implement the Guard

Option A: Custom ESLint Rule (for code patterns)

Create or extend eslint.config.mjs:

// Example: prevent db.prepare().all() without type assertion
{
  rules: {
    'no-restricted-syntax': ['error', {
      selector: 'CallExpression[callee.property.name="all"]:not([parent.type="TSAsExpression"])',
      message: 'db.prepare().all() must have a type assertion: .all() as SomeType[]'
    }]
  }
}

Option B: Import Restriction (for architecture violations)

// Example: prevent sidecar/ from importing engine-specific code
{
  rules: {
    'no-restricted-imports': ['error', {
      patterns: [{
        group: ['cc', 'cc/*', '@cocos/*'],
        message: 'Engine imports not allowed outside adapters/'
      }]
    }]
  }
}

Option C: Test Guard (for logic invariants)

// Example: ensure Safety Invariants can't be overridden
describe('SI override resistance', () => {
  it('permissive constitution cannot override SI-1', () => {
    // Create maximally permissive constitution
    // Verify SI-1 still blocks
  });
});

Option D: CI Script (for complex checks)

#!/bin/bash
# scripts/check-no-floating-promises.sh
VIOLATIONS=$(grep -rn "^\s*\w\+Async()" src/ --include="*.ts" | grep -v "await\|void\|\.then\|\.catch")
if [ -n "$VIOLATIONS" ]; then
  echo "Floating promises found:"
  echo "$VIOLATIONS"
  exit 1
fi

Step 3: Verify the Guard Works

  1. Positive test: Introduce the bad pattern → guard catches it
  2. Negative test: Clean code → guard passes
  3. Integration: Add to pre-commit (lefthook) or CI
# Test that the guard catches the bad pattern
echo "const x: any = 1;" > /tmp/test-guard.ts
bun run lint /tmp/test-guard.ts 2>&1 | grep "error"
# Should show the lint error
rm /tmp/test-guard.ts

Step 4: Document the Guard

Add to CLAUDE.md or project docs:

### Guard: <pattern name>
- **What**: <what it prevents>
- **Why**: <the incident that led to this guard>
- **How**: <ESLint rule / test / CI script>
- **Verification**: `<command to verify guard works>`

Operation 3: Audit

Run a full audit across all categories.

Workflow

  1. Run scan for each category: type-safety, error-handling, security, testing, dead-code
  2. Aggregate findings into a single report
  3. Identify top 3 recurring patterns
  4. For each pattern, recommend a guard mechanism

Output

## Full Audit Report

**Date**: YYYY-MM-DD
**Total findings**: N

### By Category
| Category | P0 | P1 | P2 | Top Pattern |
|----------|----|----|----|---------  ---|
| type-safety | 2 | 15 | 30 | unsafe DB query returns |
| error-handling | 0 | 5 | 10 | defensive try/catch |
| security | 1 | 2 | 0 | hardcoded URL |
| testing | 0 | 3 | 8 | setTimeout in tests |
| dead-code | 0 | 2 | 5 | unused exports |

### Top 3 Patterns to Guard

1. **<pattern>** — N occurrences, guard: <mechanism>
2. **<pattern>** — N occurrences, guard: <mechanism>
3. **<pattern>** — N occurrences, guard: <mechanism>

### Recommended Actions
1. [ ] Fix P0 issues immediately
2. [ ] Create batch-fix issues for P1 patterns
3. [ ] Add guards for top 3 patterns

Key Principles

  1. Fix by pattern, not by instance — if you find 10 occurrences of the same problem, fix all 10 in one PR and add a guard
  2. Every fix needs a guard — the fix is only half done without regression prevention
  3. Automation > documentation — a lint rule is better than a CLAUDE.md note; a CI check is better than a code comment
  4. Incremental hardening — don't try to fix everything at once. Pick the top pattern, fix it, guard it, move to the next
  5. The guard IS the documentation — the lint rule message or test name explains why the pattern is forbidden

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.