Loading...
Loading...
Detect patterns, anomalies, and trends in code and data. Use when identifying code smells, finding security vulnerabilities, or discovering recurring patterns. Handles regex patterns, AST analysis, and statistical anomaly detection.
npx skill4agent add supercent-io/skills-template pattern-detection# 50줄 이상 함수 찾기
grep -n "function\|def\|func " **/*.{js,ts,py,go} | \
while read line; do
file=$(echo $line | cut -d: -f1)
linenum=$(echo $line | cut -d: -f2)
# 함수 길이 계산 로직
done# 유사한 코드 블록 검색
grep -rn "if.*==.*null" --include="*.ts" .
grep -rn "try\s*{" --include="*.java" . | wc -l# 하드코딩된 숫자 검색
grep -rn "[^a-zA-Z][0-9]{2,}[^a-zA-Z]" --include="*.{js,ts}" .# 문자열 연결로 SQL 쿼리 생성
grep -rn "query.*+.*\$\|execute.*%s\|query.*f\"" --include="*.py" .
grep -rn "SELECT.*\+.*\|\|" --include="*.{js,ts}" .# 비밀번호, API 키 패턴
grep -riE "(password|secret|api_key|apikey)\s*=\s*['\"][^'\"]+['\"]" --include="*.{js,ts,py,java}" .
# AWS 키 패턴
grep -rE "AKIA[0-9A-Z]{16}" .# eval, exec 사용
grep -rn "eval\(.*\)\|exec\(.*\)" --include="*.{py,js}" .
# innerHTML 사용
grep -rn "innerHTML\s*=" --include="*.{js,ts}" .# 사용되지 않는 임포트 후보
grep -rn "^import\|^from.*import" --include="*.py" . | \
awk -F: '{print $3}' | sort | uniq -c | sort -rn# 미완성 코드 찾기
grep -rn "TODO\|FIXME\|HACK\|XXX" --include="*.{js,ts,py}" .# 빈 catch 블록
grep -rn "catch.*{[\s]*}" --include="*.{js,ts,java}" .
# 무시되는 에러
grep -rn "except:\s*pass" --include="*.py" .import re
patterns = {
'email': r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}',
'phone': r'\d{3}[-.\s]?\d{4}[-.\s]?\d{4}',
'ip_address': r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',
'credit_card': r'\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}',
'ssn': r'\d{3}-\d{2}-\d{4}',
}
def detect_sensitive_data(text):
found = {}
for name, pattern in patterns.items():
matches = re.findall(pattern, text)
if matches:
found[name] = len(matches)
return foundimport numpy as np
from scipy import stats
def detect_anomalies_zscore(data, threshold=3):
"""Z-score 기반 이상치 탐지"""
z_scores = np.abs(stats.zscore(data))
return np.where(z_scores > threshold)[0]
def detect_anomalies_iqr(data, k=1.5):
"""IQR 기반 이상치 탐지"""
q1, q3 = np.percentile(data, [25, 75])
iqr = q3 - q1
lower = q1 - k * iqr
upper = q3 + k * iqr
return np.where((data < lower) | (data > upper))[0]import pandas as pd
def analyze_trend(df, date_col, value_col):
"""시계열 트렌드 분석"""
df[date_col] = pd.to_datetime(df[date_col])
df = df.sort_values(date_col)
# 이동 평균
df['ma_7'] = df[value_col].rolling(window=7).mean()
df['ma_30'] = df[value_col].rolling(window=30).mean()
# 성장률
df['growth'] = df[value_col].pct_change() * 100
# 트렌드 방향
recent_trend = df['ma_7'].iloc[-1] > df['ma_30'].iloc[-1]
return {
'trend_direction': 'up' if recent_trend else 'down',
'avg_growth': df['growth'].mean(),
'volatility': df[value_col].std()
}# 패턴 감지 리포트
## 요약
- 스캔 파일 수: XXX
- 감지된 패턴: XX
- 심각도 높음: X
- 심각도 중간: X
- 심각도 낮음: X
## 감지된 패턴
### 보안 취약점 (HIGH)
| 파일 | 라인 | 패턴 | 설명 |
|------|------|------|------|
| file.js | 42 | hardcoded-secret | API 키 하드코딩 |
### 코드 스멜 (MEDIUM)
| 파일 | 라인 | 패턴 | 설명 |
|------|------|------|------|
| util.py | 100 | long-function | 함수 길이 150줄 |
## 권장 조치
1. [조치 1]
2. [조치 2]