본문으로 건너뛰기
cccskills
무료GitHub에 공개

code-pattern-extractor

Analyze codebases to identify reusable code patterns, duplications, and implementation patterns for future development. Use when refactoring code, identifying technical debt, finding opportunities for abstraction, or documenting common patterns in a directory or module. Outputs pattern catalogs, refactoring suggestions, and reusable template code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md6.0 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Code Pattern Extractor

Overview

Systematically analyze code in directories or modules to identify recurring patterns, code duplication, and implementation patterns that can be abstracted into reusable components, utilities, or design patterns.

Workflow

1. Define Analysis Scope

Identify the code to analyze:

  • Directory/module: Analyze all files in a specific directory
  • File set: Analyze a specific set of related files
  • Component: Analyze files related to a specific feature or component

Use Glob to find relevant files:

**/*.js, **/*.py, **/*.go, etc.

2. Scan for Code Duplication

Identify repeated code blocks that appear multiple times:

Look for:

  • Similar function implementations with minor variations
  • Repeated code blocks (>5 lines) across files
  • Copy-pasted code with slight modifications
  • Similar class structures or method patterns

Analysis criteria:

  • Similarity threshold: >70% code similarity
  • Minimum size: 5+ lines of code
  • Frequency: Appears 3+ times

3. Identify Implementation Patterns

Find recurring implementation approaches:

Common patterns:

  • API call patterns: Similar fetch/request handling
  • Error handling: Repeated try-catch or error checking
  • Data validation: Similar input validation logic
  • Data transformation: Repeated mapping/filtering operations
  • State management: Similar state update patterns
  • Configuration: Repeated configuration setup

Example patterns to detect:

// Pattern: API call with error handling
async function fetchX() {
  try {
    const response = await fetch(url);
    if (!response.ok) throw new Error();
    return await response.json();
  } catch (error) {
    console.error(error);
    return null;
  }
}

4. Categorize Patterns

Group identified patterns by type and impact:

Categories:

  • High-value: Appears frequently (5+ times), significant code size
  • Medium-value: Appears moderately (3-4 times), moderate complexity
  • Low-value: Appears rarely (2 times), simple code

Pattern types:

  • Utility functions (data processing, formatting, validation)
  • API/network patterns (requests, responses, error handling)
  • UI patterns (component structures, event handling)
  • Business logic patterns (calculations, rules, workflows)

5. Generate Pattern Catalog

Document each identified pattern:

Pattern entry format:

## Pattern: [Descriptive Name]

**Type**: [Utility/API/UI/Business Logic]
**Frequency**: [Number of occurrences]
**Impact**: [High/Medium/Low]

**Description**: [What the pattern does]

**Current implementations**:
- `file1.js:45-60` - [Brief context]
- `file2.js:120-135` - [Brief context]
- `file3.js:89-104` - [Brief context]

**Common variations**:
- [Variation 1 description]
- [Variation 2 description]

6. Generate Refactoring Suggestions

For each high-value pattern, provide refactoring recommendations:

Suggestion format:

### Refactoring: Extract [Pattern Name]

**Current state**: Pattern appears in [N] locations with [X]% code duplication

**Proposed solution**: Extract into [utility function/class/hook/module]

**Benefits**:
- Reduce code duplication by ~[N] lines
- Centralize logic for easier maintenance
- Improve testability

**Implementation approach**:
1. Create new file: `utils/[pattern-name].js`
2. Extract common logic with parameters for variations
3. Replace [N] occurrences with function calls
4. Add unit tests

**Estimated effort**: [Small/Medium/Large]

7. Generate Template Code

Create reusable template implementations for high-value patterns:

Template format:

/**
 * [Pattern description]
 *
 * @param {type} param1 - [Description]
 * @param {type} param2 - [Description]
 * @returns {type} [Description]
 */
function patternTemplate(param1, param2) {
  // Extracted common logic
  // Parameterized variations
  // Return standardized result
}

Include:

  • Function signature with parameters for variations
  • Documentation comments
  • Error handling
  • Type annotations (if applicable)
  • Usage examples

Output Structure

Organize findings into a comprehensive report:

# Code Pattern Analysis: [Directory/Module Name]

## Summary
- Files analyzed: [N]
- Patterns identified: [N]
- High-value patterns: [N]
- Estimated duplication: [N] lines

## Pattern Catalog
[List of all identified patterns with details]

## Refactoring Suggestions
[Prioritized list of refactoring opportunities]

## Template Code
[Reusable implementations for high-value patterns]

## Next Steps
[Recommended actions prioritized by impact]

Pattern Detection Heuristics

Code duplication detection:

  • Compare function bodies for structural similarity
  • Ignore variable names and minor formatting differences
  • Focus on logic flow and operations

Implementation pattern detection:

  • Look for similar function signatures
  • Identify repeated import patterns
  • Find similar control flow structures (if-else, loops, try-catch)
  • Detect repeated library usage patterns

Abstraction opportunities:

  • Multiple functions with similar purpose but different parameters
  • Repeated setup/teardown code
  • Similar data transformations
  • Parallel class hierarchies

Tips

  • Start with high-frequency patterns for maximum impact
  • Consider language-specific idioms when suggesting abstractions
  • Balance DRY principle with code clarity (don't over-abstract)
  • Include migration path in refactoring suggestions
  • Prioritize patterns that improve maintainability, not just reduce lines
  • Consider existing project architecture when suggesting abstractions
  • Document trade-offs (flexibility vs. simplicity)
  • For large codebases, analyze one module at a time

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Applies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

ArabelaTso의 스킬 모두 보기

이 스킬의 문제 신고