AgentSkillsCN

antipattern-detect

自动触发的技能,可分析Linting失败、测试结果以及代码评审反馈,从而发现反复出现的反模式。并将发现存储于knowledge_base.yml(YAML形式的权威知识源)中,通过learning_capture.sh完成记录。

SKILL.md
--- frontmatter
name: antipattern-detect
description: |
  Auto-triggered skill that analyzes linting failures, test results, and code
  review feedback to detect recurring antipatterns. Stores findings in
  knowledge_base.yml (YAML source of truth) via learning_capture.sh.

Antipattern Detection Skill

This skill automatically activates after linting failures, test failures, or code review feedback to identify recurring antipatterns. It stores findings in ~/.claude/config/knowledge_base.yml (the YAML source of truth) via learning_capture.sh. The human-readable docs/KNOWLEDGE_BASE.md is auto-generated from the YAML by learning_capture.sh sync-docs.

Trigger Criteria

Activate when any of the following are detected in the current session:

TriggerDetection Method
Lint failureExit code != 0 from ruff, eslint, golangci-lint, tflint
Test failureExit code != 0 from pytest, go test, vitest, terratest
Security findingAny finding from bandit, gosec, npm audit, tfsec
Repeated patternSame issue type seen 3+ times across files
Code review feedbackParallel agent consensus flags a recurring concern

Analysis Process

Step 1: Collect Failure Data

Gather from the current session:

  • Linter output (error codes, rule names, affected lines)
  • Test output (failure messages, assertion errors)
  • Security scan output (vulnerability types, severity)
  • Agent review feedback (concerns raised by 2+ agents)

Step 2: Pattern Classification

Classify each failure into an antipattern category:

CategoryExamples
securityHardcoded secrets, SQL injection, unsafe deserialization
error-handlingBare exceptions, silent failures, missing error boundaries
performanceN+1 queries, unbounded loops, missing pagination
type-safetyMissing type hints, any overuse, unchecked casts
testingMissing edge cases, brittle assertions, test pollution
architectureCircular imports, god classes, tight coupling
namingMisleading names, inconsistent conventions, abbreviations
duplicationCopy-paste code, reimplemented stdlib, redundant logic

Step 3: Deduplication

Before adding a new antipattern, check for existing entries in the knowledge base:

bash
~/.claude/scripts/learning_capture.sh query --category antipattern --language <LANG> --format llm
  • If a matching entry exists (same category + language + similar description), increment it:

    bash
    ~/.claude/scripts/learning_capture.sh increment <ID>
    
  • Only create a new entry if no similar pattern is documented

Step 4: Store Entry

For each new antipattern, store it in the YAML knowledge base:

bash
~/.claude/scripts/learning_capture.sh add \
  --category antipattern \
  --language <language> \
  --title "<short title>" \
  --description "<1-2 sentence problem description and recommended fix>" \
  --tags "<comma-separated tags>" \
  --confidence <high|medium|low> \
  --source antipattern-detect

After storing all new entries, regenerate the human-readable docs:

bash
~/.claude/scripts/learning_capture.sh sync-docs

Storage

Source of truth: ~/.claude/config/knowledge_base.yml (machine-readable YAML)

Entries are stored via learning_capture.sh add which handles:

  • Automatic ID generation (KB-NNN format)
  • YAML validation before writing
  • Header comment preservation

Human-readable view: docs/KNOWLEDGE_BASE.md (auto-generated)

Regenerated by learning_capture.sh sync-docs. Do not edit this file directly.


Non-Blocking Behavior

This skill follows the same non-blocking pattern as code-quality:

  • Never blocks user workflow or command execution
  • Reports inline when an antipattern is detected
  • Writes to knowledge_base.yml via learning_capture.sh after primary task completes
  • Suggests fixes but does not auto-apply changes

Integration

This skill complements other skills:

SkillRelationship
code-qualityFeeds security/quality findings into antipattern detection
learning-loopShares knowledge_base.yml as the common data store
verifyLint/test failures trigger antipattern analysis

When both code-quality and antipattern-detect trigger:

  1. code-quality provides immediate inline feedback
  2. antipattern-detect documents the pattern for future reference
  3. Results are complementary, not duplicated

Safety Checks

  • Never modify source code -- only writes to knowledge_base.yml via learning_capture.sh
  • learning_capture.sh validates YAML before writing
  • Cap entries at 500 per knowledge base file (learning_capture.sh limit)
  • Sanitize code examples to remove actual secrets or credentials
  • sync-docs regenerates docs/KNOWLEDGE_BASE.md -- do not edit that file directly