์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐Ÿค– ํŒŒ์ด์ฌ์œผ๋กœ ์ฝ”๋“œ ๋ฆฌ๋ทฐ์šฉ AI ๋„์šฐ๋ฏธ ๋งŒ๋“ค๊ธฐ: ๊ฐœ๋ฐœ์ž์˜ ๋“ ๋“ ํ•œ ๋™๋ฃŒ ํƒ„์ƒ์‹œํ‚ค๊ธฐ

๐Ÿค– ํŒŒ์ด์ฌ์œผ๋กœ ์ฝ”๋“œ ๋ฆฌ๋ทฐ์šฉ AI ๋„์šฐ๋ฏธ ๋งŒ๋“ค๊ธฐ: ๊ฐœ๋ฐœ์ž์˜ ๋“ ๋“ ํ•œ ๋™๋ฃŒ ํƒ„์ƒ์‹œํ‚ค๊ธฐ

AI๊ฐ€ ๋‹น์‹ ์˜ ์ฝ”๋“œ๋ฅผ ๋ฆฌ๋ทฐํ•ด์ค€๋‹ค๋ฉด? ์ƒ์ƒ์ด ํ˜„์‹ค์ด ๋˜๋Š” ์ˆœ๊ฐ„!

๐Ÿ’ก ์—ฌ๋Ÿฌ๋ถ„, ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋ฐ›์„ ๋•Œ ์–ด๋–ค ๊ธฐ๋ถ„์ด์‹ ๊ฐ€์š”? ์†”์งํžˆ ๋งํ•ด์„œ ์ข€ ๋–จ๋ฆฌ์ฃ ? "์ด ๋ถ€๋ถ„ ์™œ ์ด๋ ‡๊ฒŒ ์งฐ์–ด?"๋ผ๋Š” ์งˆ๋ฌธ์— ์‹์€๋•€์ด ๋‚˜๊ธฐ๋„ ํ•˜๊ณ ์š”. ํ•˜์ง€๋งŒ ๋™์‹œ์— ์ฝ”๋“œ ๋ฆฌ๋ทฐ๋Š” ๊ฐœ๋ฐœ์ž๋กœ ์„ฑ์žฅํ•˜๋Š” ๊ฐ€์žฅ ๋น ๋ฅธ ์ง€๋ฆ„๊ธธ์ด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. ๐Ÿš€

๊ทธ๋Ÿฐ๋ฐ ๋งŒ์•ฝ 24์‹œ๊ฐ„ ์–ธ์ œ๋“ ์ง€, ๊ธฐ๋ถ„ ๋‚˜์˜์ง€ ์•Š๊ฒŒ, ์นœ์ ˆํ•˜๊ฒŒ ์ฝ”๋“œ๋ฅผ ๋ฆฌ๋ทฐํ•ด์ฃผ๋Š” AI ๋„์šฐ๋ฏธ๊ฐ€ ์žˆ๋‹ค๋ฉด ์–ด๋–จ๊นŒ์š”? ์˜ค๋Š˜์€ ๋ฐ”๋กœ ๊ทธ ๊ฟˆ๊ฐ™์€ ๋„๊ตฌ๋ฅผ ํŒŒ์ด์ฌ์œผ๋กœ ์ง์ ‘ ๋งŒ๋“ค์–ด๋ณด๋Š” ์—ฌ์ •์„ ํ•จ๊ป˜ ๋– ๋‚˜๋ณผ ๊ฑฐ์˜ˆ์š”! ๐Ÿ˜Š

def review_code(): issues = analyze(code) suggestions = generate() return feedback Run Review Ready AI Review Results โš ๏ธ Issue Found Variable naming could be improved โœ“ Good Practice Proper error handling detected ๐Ÿ’ก Suggestion Consider using list comprehension AI Analysis ๐Ÿค–

๐ŸŽฏ ์™œ ์ฝ”๋“œ ๋ฆฌ๋ทฐ AI ๋„์šฐ๋ฏธ๊ฐ€ ํ•„์š”ํ• ๊นŒ?

์ฝ”๋“œ ๋ฆฌ๋ทฐ๋Š” ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ์—์„œ ์ •๋ง ์ค‘์š”ํ•œ ๊ณผ์ •์ด์—์š”. ํ•˜์ง€๋งŒ ํ˜„์‹ค์€ ์–ด๋–ค๊ฐ€์š”?

๐Ÿค” ํ˜„์‹ค์ ์ธ ๋ฌธ์ œ๋“ค: ์‹œ๊ฐ„ ๋ถ€์กฑ ๋ฐ”์œ ํŒ€์›๋“ค์€ ์ฝ”๋“œ ๋ฆฌ๋ทฐํ•  ์‹œ๊ฐ„์ด ์—†์–ด์š”
์ผ๊ด€์„ฑ ๋ถ€์กฑ ๋ฆฌ๋ทฐ์–ด๋งˆ๋‹ค ๊ธฐ์ค€์ด ๋‹ฌ๋ผ์š”
์ฆ‰๊ฐ์„ฑ ๋ถ€์กฑ ๋ฆฌ๋ทฐ ๋ฐ›๊ธฐ๊นŒ์ง€ ๋ช‡ ์‹œ๊ฐ„, ์‹ฌ์ง€์–ด ๋ฉฐ์น ์ด ๊ฑธ๋ฆฌ๊ธฐ๋„ ํ•ด์š”
์‹ฌ๋ฆฌ์  ๋ถ€๋‹ด ์„ ๋ฐฐ ๊ฐœ๋ฐœ์ž์—๊ฒŒ ๋ฆฌ๋ทฐ ์š”์ฒญํ•˜๊ธฐ๊ฐ€ ๋ถ€๋‹ด์Šค๋Ÿฌ์›Œ์š”
ํ•™์Šต ๊ธฐํšŒ ์†์‹ค ํ˜ผ์ž ๊ณต๋ถ€ํ•  ๋•Œ๋Š” ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์„ ์ˆ˜๊ฐ€ ์—†์ฃ 

์ด๋Ÿฐ ๋ฌธ์ œ๋“ค์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด AI ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋„์šฐ๋ฏธ๊ฐ€ ๋“ฑ์žฅํ–ˆ์–ด์š”! ๐ŸŽ‰

ํŠนํžˆ ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ฐ•์˜๋‚˜ ์ฝ”๋“œ ๋ฆฌ๋ทฐ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋ถ„๋“ค์—๊ฒŒ๋Š” ์ด๋Ÿฐ ๋„๊ตฌ๊ฐ€ ์ •๋ง ์œ ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”. ํ•™์ƒ๋“ค์—๊ฒŒ ์ฆ‰๊ฐ์ ์ธ ํ”ผ๋“œ๋ฐฑ์„ ์ œ๊ณตํ•˜๋ฉด์„œ๋„, ๊ฐ•์‚ฌ๋‹˜์˜ ์‹œ๊ฐ„์„ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ๊ฑฐ๋“ ์š”.

๐Ÿ› ๏ธ ํ”„๋กœ์ ํŠธ ์ค€๋น„ํ•˜๊ธฐ: ํ•„์š”ํ•œ ๊ฒƒ๋“ค

์ž, ์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ์‹œ์ž‘ํ•ด๋ณผ๊นŒ์š”? ๋จผ์ € ํ•„์š”ํ•œ ๋„๊ตฌ๋“ค์„ ์ฑ™๊ฒจ๋ด…์‹œ๋‹ค!

๐Ÿ“ฆ 1๋‹จ๊ณ„: ๊ธฐ๋ณธ ํ™˜๊ฒฝ ์„ค์ •

ํŒŒ์ด์ฌ 3.8 ์ด์ƒ์ด ํ•„์š”ํ•ด์š”. ์š”์ฆ˜์€ 3.10์ด๋‚˜ 3.11์„ ์ถ”์ฒœ๋“œ๋ ค์š”. ์„ฑ๋Šฅ๋„ ์ข‹๊ณ  ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ๋“ค๋„ ๋งŽ๊ฑฐ๋“ ์š”!

# ํŒŒ์ด์ฌ ๋ฒ„์ „ ํ™•์ธ
python --version

# ๊ฐ€์ƒํ™˜๊ฒฝ ์ƒ์„ฑ (ํ”„๋กœ์ ํŠธ ํด๋”์—์„œ)
python -m venv code_review_env

# ๊ฐ€์ƒํ™˜๊ฒฝ ํ™œ์„ฑํ™”
# Windows
code_review_env\Scripts\activate
# Mac/Linux
source code_review_env/bin/activate

๐Ÿ“š 2๋‹จ๊ณ„: ํ•„์ˆ˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

์šฐ๋ฆฌ ํ”„๋กœ์ ํŠธ์— ํ•„์š”ํ•œ ํ•ต์‹ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์„ ์„ค์น˜ํ•ด๋ด…์‹œ๋‹ค:

# requirements.txt ํŒŒ์ผ ๋‚ด์šฉ
openai==1.3.0          # OpenAI API ์‚ฌ์šฉ
anthropic==0.7.0       # Claude API ์‚ฌ์šฉ (์„ ํƒ์‚ฌํ•ญ)
python-dotenv==1.0.0   # ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๊ด€๋ฆฌ
ast-parser==0.2.0      # ํŒŒ์ด์ฌ ์ฝ”๋“œ ํŒŒ์‹ฑ
pylint==3.0.0          # ์ •์  ๋ถ„์„
black==23.11.0         # ์ฝ”๋“œ ํฌ๋งทํŒ… ์ฒดํฌ
radon==6.0.1           # ๋ณต์žก๋„ ๋ถ„์„
gitpython==3.1.40      # Git ํ†ตํ•ฉ
flask==3.0.0           # ์›น ์ธํ„ฐํŽ˜์ด์Šค (์„ ํƒ์‚ฌํ•ญ)

# ์„ค์น˜ ๋ช…๋ น์–ด
pip install -r requirements.txt

๐Ÿ’ก Pro Tip: OpenAI API๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด API ํ‚ค๊ฐ€ ํ•„์š”ํ•ด์š”. openai.com์—์„œ ๊ณ„์ •์„ ๋งŒ๋“ค๊ณ  API ํ‚ค๋ฅผ ๋ฐœ๊ธ‰๋ฐ›์œผ์„ธ์š”. ๋ฌด๋ฃŒ ํฌ๋ ˆ๋”ง๋„ ์ œ๊ณต๋˜๋‹ˆ ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์ข‹์•„์š”! ๐ŸŽ

๐Ÿ—๏ธ ์•„ํ‚คํ…์ฒ˜ ์„ค๊ณ„: ์ „์ฒด ๊ตฌ์กฐ ์ดํ•ดํ•˜๊ธฐ

์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ ์ „์— ์ „์ฒด ๊ตฌ์กฐ๋ฅผ ๋จผ์ € ์ดํ•ดํ•ด๋ด…์‹œ๋‹ค. ์šฐ๋ฆฌ AI ๋„์šฐ๋ฏธ๋Š” ํฌ๊ฒŒ 5๊ฐœ์˜ ๋ชจ๋“ˆ๋กœ ๊ตฌ์„ฑ๋  ๊ฑฐ์˜ˆ์š”:

๐ŸŽจ ์‹œ์Šคํ…œ ๊ตฌ์„ฑ์š”์†Œ:

๋ชจ๋“ˆ ์—ญํ•  ํ•ต์‹ฌ ๊ธฐ๋Šฅ
์ฝ”๋“œ ํŒŒ์„œ ์ฝ”๋“œ ๋ถ„์„ AST ํŒŒ์‹ฑ, ๊ตฌ์กฐ ๋ถ„์„, ๋ฉ”ํŠธ๋ฆญ ์ถ”์ถœ
์ •์  ๋ถ„์„๊ธฐ ๊ธฐ๋ณธ ๊ฒ€์‚ฌ ๋ฌธ๋ฒ• ์˜ค๋ฅ˜, ์Šคํƒ€์ผ ์œ„๋ฐ˜, ๋ณต์žก๋„ ์ธก์ •
AI ์—”์ง„ ์ง€๋Šฅํ˜• ๋ฆฌ๋ทฐ GPT/Claude ํ™œ์šฉ, ์ปจํ…์ŠคํŠธ ์ดํ•ด, ์ œ์•ˆ ์ƒ์„ฑ
๋ฆฌํฌํŠธ ์ƒ์„ฑ๊ธฐ ๊ฒฐ๊ณผ ์ถœ๋ ฅ ๋งˆํฌ๋‹ค์šด/HTML ๋ฆฌํฌํŠธ, ์šฐ์„ ์ˆœ์œ„ ์ •๋ ฌ
์ธํ„ฐํŽ˜์ด์Šค ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ CLI/์›น UI, ์„ค์ • ๊ด€๋ฆฌ

์ด์ œ ๊ฐ ๋ชจ๋“ˆ์„ ํ•˜๋‚˜์”ฉ ๊ตฌํ˜„ํ•ด๋ณผ๊นŒ์š”? ๐Ÿ˜Š

๐Ÿ” 1๋‹จ๊ณ„: ์ฝ”๋“œ ํŒŒ์„œ ๋งŒ๋“ค๊ธฐ

์ฒซ ๋ฒˆ์งธ๋กœ ๋งŒ๋“ค ๊ฑด ์ฝ”๋“œ ํŒŒ์„œ์˜ˆ์š”. ํŒŒ์ด์ฌ์˜ ast (Abstract Syntax Tree) ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ๊ตฌ์กฐ์ ์œผ๋กœ ๋ถ„์„ํ•  ์ˆ˜ ์žˆ์–ด์š”.

import ast
import os
from typing import Dict, List, Any
from dataclasses import dataclass

@dataclass
class CodeMetrics:
    """์ฝ”๋“œ ๋ฉ”ํŠธ๋ฆญ์„ ์ €์žฅํ•˜๋Š” ๋ฐ์ดํ„ฐ ํด๋ž˜์Šค"""
    total_lines: int
    code_lines: int
    comment_lines: int
    blank_lines: int
    functions: List[str]
    classes: List[str]
    imports: List[str]
    complexity_score: float

class CodeParser:
    """ํŒŒ์ด์ฌ ์ฝ”๋“œ๋ฅผ ํŒŒ์‹ฑํ•˜๊ณ  ๋ถ„์„ํ•˜๋Š” ํด๋ž˜์Šค"""
    
    def __init__(self, code: str):
        self.code = code
        self.tree = None
        self.metrics = None
        
    def parse(self) -> bool:
        """์ฝ”๋“œ๋ฅผ AST๋กœ ํŒŒ์‹ฑ"""
        try:
            self.tree = ast.parse(self.code)
            return True
        except SyntaxError as e:
            print(f"โŒ ๋ฌธ๋ฒ• ์˜ค๋ฅ˜ ๋ฐœ๊ฒฌ: {e}")
            return False
    
    def extract_metrics(self) -> CodeMetrics:
        """์ฝ”๋“œ์—์„œ ๋‹ค์–‘ํ•œ ๋ฉ”ํŠธ๋ฆญ์„ ์ถ”์ถœ"""
        if not self.tree:
            raise ValueError("๋จผ์ € parse()๋ฅผ ํ˜ธ์ถœํ•ด์ฃผ์„ธ์š”!")
        
        lines = self.code.split('\n')
        total_lines = len(lines)
        blank_lines = sum(1 for line in lines if not line.strip())
        comment_lines = sum(1 for line in lines if line.strip().startswith('#'))
        code_lines = total_lines - blank_lines - comment_lines
        
        # ํ•จ์ˆ˜์™€ ํด๋ž˜์Šค ์ถ”์ถœ
        functions = []
        classes = []
        imports = []
        
        for node in ast.walk(self.tree):
            if isinstance(node, ast.FunctionDef):
                functions.append(node.name)
            elif isinstance(node, ast.ClassDef):
                classes.append(node.name)
            elif isinstance(node, (ast.Import, ast.ImportFrom)):
                if isinstance(node, ast.Import):
                    imports.extend([alias.name for alias in node.names])
                else:
                    imports.append(node.module)
        
        # ๊ฐ„๋‹จํ•œ ๋ณต์žก๋„ ์ ์ˆ˜ ๊ณ„์‚ฐ
        complexity = self._calculate_complexity()
        
        self.metrics = CodeMetrics(
            total_lines=total_lines,
            code_lines=code_lines,
            comment_lines=comment_lines,
            blank_lines=blank_lines,
            functions=functions,
            classes=classes,
            imports=imports,
            complexity_score=complexity
        )
        
        return self.metrics
    
    def _calculate_complexity(self) -> float:
        """์ˆœํ™˜ ๋ณต์žก๋„ ๊ณ„์‚ฐ (๊ฐ„๋‹จํ•œ ๋ฒ„์ „)"""
        complexity = 1  # ๊ธฐ๋ณธ ๋ณต์žก๋„
        
        for node in ast.walk(self.tree):
            # ๋ถ„๊ธฐ๋ฌธ๋งˆ๋‹ค ๋ณต์žก๋„ ์ฆ๊ฐ€
            if isinstance(node, (ast.If, ast.While, ast.For)):
                complexity += 1
            elif isinstance(node, ast.ExceptHandler):
                complexity += 1
            elif isinstance(node, ast.BoolOp):
                complexity += len(node.values) - 1
        
        return complexity
    
    def get_function_info(self, func_name: str) -> Dict[str, Any]:
        """ํŠน์ • ํ•จ์ˆ˜์˜ ์ƒ์„ธ ์ •๋ณด ์ถ”์ถœ"""
        for node in ast.walk(self.tree):
            if isinstance(node, ast.FunctionDef) and node.name == func_name:
                return {
                    'name': node.name,
                    'args': [arg.arg for arg in node.args.args],
                    'line_number': node.lineno,
                    'docstring': ast.get_docstring(node),
                    'decorators': [d.id for d in node.decorator_list if isinstance(d, ast.Name)]
                }
        return None

# ์‚ฌ์šฉ ์˜ˆ์‹œ
if __name__ == "__main__":
    sample_code = """
def calculate_sum(numbers):
    '''์ˆซ์ž ๋ฆฌ์ŠคํŠธ์˜ ํ•ฉ์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค'''
    total = 0
    for num in numbers:
        if num > 0:
            total += num
    return total

class DataProcessor:
    def __init__(self):
        self.data = []
    
    def process(self):
        pass
"""
    
    parser = CodeParser(sample_code)
    if parser.parse():
        metrics = parser.extract_metrics()
        print(f"๐Ÿ“Š ์ฝ”๋“œ ๋ฉ”ํŠธ๋ฆญ:")
        print(f"  ์ „์ฒด ๋ผ์ธ: {metrics.total_lines}")
        print(f"  ์ฝ”๋“œ ๋ผ์ธ: {metrics.code_lines}")
        print(f"  ํ•จ์ˆ˜: {', '.join(metrics.functions)}")
        print(f"  ํด๋ž˜์Šค: {', '.join(metrics.classes)}")
        print(f"  ๋ณต์žก๋„: {metrics.complexity_score}")

๐ŸŽ“ ํ•™์Šต ํฌ์ธํŠธ: AST(Abstract Syntax Tree)๋Š” ์ฝ”๋“œ๋ฅผ ํŠธ๋ฆฌ ๊ตฌ์กฐ๋กœ ํ‘œํ˜„ํ•œ ๊ฑฐ์˜ˆ์š”. ๋งˆ์น˜ ๋ฌธ์žฅ์„ ์ฃผ์–ด, ๋™์‚ฌ, ๋ชฉ์ ์–ด๋กœ ๋ถ„ํ•ดํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์ฝ”๋“œ๋ฅผ ๊ตฌ์กฐ์ ์œผ๋กœ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค˜์š”. ์ด๊ฑธ ํ™œ์šฉํ•˜๋ฉด ๋‹จ์ˆœํžˆ ํ…์ŠคํŠธ๋กœ ์ฝ”๋“œ๋ฅผ ๋ณด๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ, ์˜๋ฏธ ๋‹จ์œ„๋กœ ๋ถ„์„ํ•  ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค! ๐ŸŒณ

๐Ÿ”ฌ 2๋‹จ๊ณ„: ์ •์  ๋ถ„์„๊ธฐ ๊ตฌ์ถ•ํ•˜๊ธฐ

์ด์ œ ์‹ค์ œ๋กœ ์ฝ”๋“œ์˜ ๋ฌธ์ œ์ ์„ ์ฐพ์•„๋‚ด๋Š” ์ •์  ๋ถ„์„๊ธฐ๋ฅผ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค. Pylint์™€ ๊ฐ™์€ ๋„๊ตฌ๋“ค์„ ํ™œ์šฉํ•  ๊ฑฐ์˜ˆ์š”.

from pylint import lint
from pylint.reporters.text import TextReporter
from io import StringIO
import subprocess
import json
from typing import List, Dict
from dataclasses import dataclass

@dataclass
class CodeIssue:
    """์ฝ”๋“œ ์ด์Šˆ๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๋ฐ์ดํ„ฐ ํด๋ž˜์Šค"""
    severity: str  # error, warning, info
    line: int
    column: int
    message: str
    rule: str
    category: str

class StaticAnalyzer:
    """์ •์  ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•˜๋Š” ํด๋ž˜์Šค"""
    
    def __init__(self, code: str, filename: str = "temp.py"):
        self.code = code
        self.filename = filename
        self.issues: List[CodeIssue] = []
    
    def run_pylint(self) -> List[CodeIssue]:
        """Pylint๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ์ฝ”๋“œ ํ’ˆ์งˆ ๊ฒ€์‚ฌ"""
        # ์ž„์‹œ ํŒŒ์ผ์— ์ฝ”๋“œ ์ €์žฅ
        with open(self.filename, 'w', encoding='utf-8') as f:
            f.write(self.code)
        
        # Pylint ์‹คํ–‰
        pylint_output = StringIO()
        reporter = TextReporter(pylint_output)
        
        try:
            lint.Run([self.filename, '--output-format=json'], 
                    reporter=reporter, exit=False)
        except Exception as e:
            print(f"โš ๏ธ Pylint ์‹คํ–‰ ์ค‘ ์˜ค๋ฅ˜: {e}")
            return []
        
        # ๊ฒฐ๊ณผ ํŒŒ์‹ฑ
        try:
            results = json.loads(pylint_output.getvalue())
            for item in results:
                issue = CodeIssue(
                    severity=item['type'],
                    line=item['line'],
                    column=item['column'],
                    message=item['message'],
                    rule=item['symbol'],
                    category='style'
                )
                self.issues.append(issue)
        except:
            pass
        
        return self.issues
    
    def check_naming_conventions(self) -> List[CodeIssue]:
        """๋„ค์ด๋ฐ ์ปจ๋ฒค์…˜ ๊ฒ€์‚ฌ"""
        import re
        issues = []
        
        lines = self.code.split('\n')
        
        # ํ•จ์ˆ˜๋ช… ๊ฒ€์‚ฌ (snake_case)
        func_pattern = re.compile(r'def\s+([A-Z][a-zA-Z0-9]*)\s*\(')
        # ํด๋ž˜์Šค๋ช… ๊ฒ€์‚ฌ (PascalCase)
        class_pattern = re.compile(r'class\s+([a-z][a-zA-Z0-9]*)\s*[:\(]')
        
        for i, line in enumerate(lines, 1):
            # ํ•จ์ˆ˜๋ช…์ด ๋Œ€๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ์šฐ
            func_match = func_pattern.search(line)
            if func_match:
                issues.append(CodeIssue(
                    severity='warning',
                    line=i,
                    column=0,
                    message=f"ํ•จ์ˆ˜๋ช… '{func_match.group(1)}'์€ snake_case๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”",
                    rule='naming-convention',
                    category='style'
                ))
            
            # ํด๋ž˜์Šค๋ช…์ด ์†Œ๋ฌธ์ž๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ์šฐ
            class_match = class_pattern.search(line)
            if class_match:
                issues.append(CodeIssue(
                    severity='warning',
                    line=i,
                    column=0,
                    message=f"ํด๋ž˜์Šค๋ช… '{class_match.group(1)}'์€ PascalCase๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”",
                    rule='naming-convention',
                    category='style'
                ))
        
        self.issues.extend(issues)
        return issues
    
    def check_complexity(self, parser) -> List[CodeIssue]:
        """๋ณต์žก๋„ ๊ฒ€์‚ฌ"""
        issues = []
        
        if parser.metrics and parser.metrics.complexity_score > 10:
            issues.append(CodeIssue(
                severity='warning',
                line=0,
                column=0,
                message=f"์ฝ”๋“œ ๋ณต์žก๋„๊ฐ€ ๋†’์Šต๋‹ˆ๋‹ค (์ ์ˆ˜: {parser.metrics.complexity_score}). ๋ฆฌํŒฉํ† ๋ง์„ ๊ณ ๋ คํ•˜์„ธ์š”.",
                rule='high-complexity',
                category='maintainability'
            ))
        
        self.issues.extend(issues)
        return issues
    
    def check_code_smells(self) -> List[CodeIssue]:
        """์ผ๋ฐ˜์ ์ธ ์ฝ”๋“œ ์Šค๋ฉœ ๊ฒ€์‚ฌ"""
        issues = []
        lines = self.code.split('\n')
        
        for i, line in enumerate(lines, 1):
            # ๋„ˆ๋ฌด ๊ธด ๋ผ์ธ
            if len(line) > 120:
                issues.append(CodeIssue(
                    severity='info',
                    line=i,
                    column=0,
                    message=f"๋ผ์ธ์ด ๋„ˆ๋ฌด ๊น๋‹ˆ๋‹ค ({len(line)}์ž). 120์ž ์ด๋‚ด๋กœ ์ค„์ด์„ธ์š”.",
                    rule='line-too-long',
                    category='style'
                ))
            
            # TODO/FIXME ์ฃผ์„
            if 'TODO' in line or 'FIXME' in line:
                issues.append(CodeIssue(
                    severity='info',
                    line=i,
                    column=0,
                    message="๋ฏธ์™„์„ฑ ์ž‘์—…์ด ์žˆ์Šต๋‹ˆ๋‹ค.",
                    rule='todo-found',
                    category='maintenance'
                ))
            
            # ํ•˜๋“œ์ฝ”๋”ฉ๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋‚˜ ํ‚ค
            if any(keyword in line.lower() for keyword in ['password', 'api_key', 'secret']):
                if '=' in line and ('"' in line or "'" in line):
                    issues.append(CodeIssue(
                        severity='error',
                        line=i,
                        column=0,
                        message="ํ•˜๋“œ์ฝ”๋”ฉ๋œ ๋น„๋ฐ€์ •๋ณด๊ฐ€ ์˜์‹ฌ๋ฉ๋‹ˆ๋‹ค. ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”.",
                        rule='hardcoded-secret',
                        category='security'
                    ))
        
        self.issues.extend(issues)
        return issues
    
    def run_all_checks(self, parser=None) -> List[CodeIssue]:
        """๋ชจ๋“  ๊ฒ€์‚ฌ ์‹คํ–‰"""
        print("๐Ÿ” ์ •์  ๋ถ„์„ ์‹œ์ž‘...")
        
        self.check_naming_conventions()
        self.check_code_smells()
        
        if parser:
            self.check_complexity(parser)
        
        # ์‹ฌ๊ฐ๋„๋ณ„๋กœ ์ •๋ ฌ
        self.issues.sort(key=lambda x: {'error': 0, 'warning': 1, 'info': 2}[x.severity])
        
        print(f"โœ… ๋ถ„์„ ์™„๋ฃŒ: {len(self.issues)}๊ฐœ์˜ ์ด์Šˆ ๋ฐœ๊ฒฌ")
        return self.issues

# ์‚ฌ์šฉ ์˜ˆ์‹œ
if __name__ == "__main__":
    sample_code = """
def CalculateTotal(items):  # ์ž˜๋ชป๋œ ๋„ค์ด๋ฐ
    password = "mypassword123"  # ๋ณด์•ˆ ์ด์Šˆ
    total = 0
    for item in items:
        if item > 0:
            if item < 100:
                if item % 2 == 0:  # ๋ณต์žก๋„ ์ฆ๊ฐ€
                    total += item
    return total
"""
    
    analyzer = StaticAnalyzer(sample_code)
    issues = analyzer.run_all_checks()
    
    for issue in issues:
        print(f"\n{issue.severity.upper()} (Line {issue.line}): {issue.message}")

โš ๏ธ ๋ณด์•ˆ ์ฃผ์˜์‚ฌํ•ญ: ์ฝ”๋“œ์— ๋น„๋ฐ€๋ฒˆํ˜ธ๋‚˜ API ํ‚ค๋ฅผ ์ง์ ‘ ์ž‘์„ฑํ•˜๋Š” ๊ฑด ์ •๋ง ์œ„ํ—˜ํ•ด์š”! ํ•ญ์ƒ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋‚˜ ๋ณ„๋„์˜ ์„ค์ • ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜์„ธ์š”. ํŠนํžˆ Git์— ์ปค๋ฐ‹ํ•˜๊ธฐ ์ „์—๋Š” ๋ฐ˜๋“œ์‹œ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๐Ÿ”’

๐Ÿค– 3๋‹จ๊ณ„: AI ์—”์ง„ ํ†ตํ•ฉํ•˜๊ธฐ

์ด์ œ ๊ฐ€์žฅ ํ•ต์‹ฌ์ ์ธ ๋ถ€๋ถ„์ด์—์š”! OpenAI์˜ GPT๋‚˜ Anthropic์˜ Claude๋ฅผ ํ™œ์šฉํ•ด์„œ ์ง€๋Šฅํ˜• ์ฝ”๋“œ ๋ฆฌ๋ทฐ๋ฅผ ๊ตฌํ˜„ํ•ด๋ด…์‹œ๋‹ค. ๐Ÿš€

import openai
from typing import List, Dict, Optional
import os
from dotenv import load_dotenv
import json

# ํ™˜๊ฒฝ๋ณ€์ˆ˜ ๋กœ๋“œ
load_dotenv()

class AIReviewEngine:
    """AI๋ฅผ ํ™œ์šฉํ•œ ์ฝ”๋“œ ๋ฆฌ๋ทฐ ์—”์ง„"""
    
    def __init__(self, api_key: Optional[str] = None, model: str = "gpt-4"):
        self.api_key = api_key or os.getenv("OPENAI_API_KEY")
        self.model = model
        openai.api_key = self.api_key
        
        if not self.api_key:
            raise ValueError("OpenAI API ํ‚ค๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค!")
    
    def create_review_prompt(self, code: str, metrics: Dict, issues: List) -> str:
        """์ฝ”๋“œ ๋ฆฌ๋ทฐ๋ฅผ ์œ„ํ•œ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ"""
        
        # ์ด์Šˆ ์š”์•ฝ
        issue_summary = "\n".join([
            f"- [{issue.severity}] Line {issue.line}: {issue.message}"
            for issue in issues[:10]  # ์ƒ์œ„ 10๊ฐœ๋งŒ
        ])
        
        prompt = f"""
๋‹น์‹ ์€ ๊ฒฝํ—˜ ๋งŽ์€ ์‹œ๋‹ˆ์–ด ๊ฐœ๋ฐœ์ž์ž…๋‹ˆ๋‹ค. ๋‹ค์Œ ํŒŒ์ด์ฌ ์ฝ”๋“œ๋ฅผ ๋ฆฌ๋ทฐํ•ด์ฃผ์„ธ์š”.

## ์ฝ”๋“œ:
```python
{code}
```

## ์ฝ”๋“œ ๋ฉ”ํŠธ๋ฆญ:
- ์ „์ฒด ๋ผ์ธ: {metrics.get('total_lines', 'N/A')}
- ์ฝ”๋“œ ๋ผ์ธ: {metrics.get('code_lines', 'N/A')}
- ํ•จ์ˆ˜ ๊ฐœ์ˆ˜: {len(metrics.get('functions', []))}
- ํด๋ž˜์Šค ๊ฐœ์ˆ˜: {len(metrics.get('classes', []))}
- ๋ณต์žก๋„ ์ ์ˆ˜: {metrics.get('complexity_score', 'N/A')}

## ๋ฐœ๊ฒฌ๋œ ์ด์Šˆ:
{issue_summary if issue_summary else '์ด์Šˆ ์—†์Œ'}

## ๋ฆฌ๋ทฐ ์š”์ฒญ์‚ฌํ•ญ:
๋‹ค์Œ ๊ด€์ ์—์„œ ์ฝ”๋“œ๋ฅผ ๋ฆฌ๋ทฐํ•ด์ฃผ์„ธ์š”:

1. **์ฝ”๋“œ ํ’ˆ์งˆ**: ๊ฐ€๋…์„ฑ, ์œ ์ง€๋ณด์ˆ˜์„ฑ, ์ผ๊ด€์„ฑ
2. **์„ค๊ณ„**: ๊ตฌ์กฐ, ํŒจํ„ด ์‚ฌ์šฉ, ๋ชจ๋“ˆํ™”
3. **์„ฑ๋Šฅ**: ๋น„ํšจ์œจ์ ์ธ ๋ถ€๋ถ„, ์ตœ์ ํ™” ๊ฐ€๋Šฅ ์˜์—ญ
4. **๋ณด์•ˆ**: ์ž ์žฌ์  ๋ณด์•ˆ ์ทจ์•ฝ์ 
5. **๋ฒ ์ŠคํŠธ ํ”„๋ž™ํ‹ฐ์Šค**: ํŒŒ์ด์ฌ ๊ด€๋ก€ ์ค€์ˆ˜ ์—ฌ๋ถ€

๊ฐ ํ•ญ๋ชฉ์— ๋Œ€ํ•ด:
- ๐Ÿ‘ ์ž˜ํ•œ ์ 
- ๐Ÿ”ง ๊ฐœ์„ ์ด ํ•„์š”ํ•œ ์ 
- ๐Ÿ’ก ๊ตฌ์ฒด์ ์ธ ๊ฐœ์„  ์ œ์•ˆ (์ฝ”๋“œ ์˜ˆ์‹œ ํฌํ•จ)

์นœ์ ˆํ•˜๊ณ  ๊ฑด์„ค์ ์ธ ํ†ค์œผ๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
"""
        return prompt
    
    def get_review(self, code: str, metrics: Dict, issues: List) -> Dict[str, any]:
        """AI ์ฝ”๋“œ ๋ฆฌ๋ทฐ ์‹คํ–‰"""
        
        print("๐Ÿค– AI ๋ฆฌ๋ทฐ ์ƒ์„ฑ ์ค‘...")
        
        prompt = self.create_review_prompt(code, metrics, issues)
        
        try:
            response = openai.ChatCompletion.create(
                model=self.model,
                messages=[
                    {
                        "role": "system",
                        "content": "๋‹น์‹ ์€ ์นœ์ ˆํ•˜๊ณ  ๊ฒฝํ—˜ ๋งŽ์€ ์‹œ๋‹ˆ์–ด ๊ฐœ๋ฐœ์ž์ž…๋‹ˆ๋‹ค. ์ฝ”๋“œ ๋ฆฌ๋ทฐ๋ฅผ ํ†ตํ•ด ์ฃผ๋‹ˆ์–ด ๊ฐœ๋ฐœ์ž๋“ค์˜ ์„ฑ์žฅ์„ ๋•์Šต๋‹ˆ๋‹ค."
                    },
                    {
                        "role": "user",
                        "content": prompt
                    }
                ],
                temperature=0.7,
                max_tokens=2000
            )
            
            review_text = response.choices[0].message.content
            
            return {
                'success': True,
                'review': review_text,
                'model': self.model,
                'tokens_used': response.usage.total_tokens
            }
            
        except Exception as e:
            print(f"โŒ AI ๋ฆฌ๋ทฐ ์ƒ์„ฑ ์‹คํŒจ: {e}")
            return {
                'success': False,
                'error': str(e)
            }
    
    def get_specific_suggestion(self, code_snippet: str, issue: str) -> str:
        """ํŠน์ • ์ฝ”๋“œ ๋ถ€๋ถ„์— ๋Œ€ํ•œ ๊ฐœ์„  ์ œ์•ˆ"""
        
        prompt = f"""
๋‹ค์Œ ์ฝ”๋“œ์— ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค:

```python
{code_snippet}
```

๋ฌธ์ œ: {issue}

์ด ์ฝ”๋“œ๋ฅผ ๊ฐœ์„ ํ•œ ๋ฒ„์ „์„ ์ž‘์„ฑํ•˜๊ณ , ์™œ ๋” ๋‚˜์€์ง€ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”.
"""
        
        try:
            response = openai.ChatCompletion.create(
                model=self.model,
                messages=[
                    {"role": "user", "content": prompt}
                ],
                temperature=0.5,
                max_tokens=500
            )
            
            return response.choices[0].message.content
            
        except Exception as e:
            return f"์ œ์•ˆ ์ƒ์„ฑ ์‹คํŒจ: {e}"
    
    def explain_concept(self, concept: str) -> str:
        """์ฝ”๋“œ ๊ฐœ๋…์ด๋‚˜ ํŒจํ„ด ์„ค๋ช…"""
        
        prompt = f"""
'{concept}'์— ๋Œ€ํ•ด ํŒŒ์ด์ฌ ์ดˆ๋ณด์ž๋„ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๊ฒŒ ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”.
๊ฐ„๋‹จํ•œ ์ฝ”๋“œ ์˜ˆ์‹œ๋„ ํฌํ•จํ•ด์ฃผ์„ธ์š”.
"""
        
        try:
            response = openai.ChatCompletion.create(
                model="gpt-3.5-turbo",  # ์„ค๋ช…์€ ๋” ์ €๋ ดํ•œ ๋ชจ๋ธ ์‚ฌ์šฉ
                messages=[
                    {"role": "user", "content": prompt}
                ],
                temperature=0.7,
                max_tokens=400
            )
            
            return response.choices[0].message.content
            
        except Exception as e:
            return f"์„ค๋ช… ์ƒ์„ฑ ์‹คํŒจ: {e}"

class SmartReviewAssistant:
    """ํ†ตํ•ฉ ๋ฆฌ๋ทฐ ์–ด์‹œ์Šคํ„ดํŠธ"""
    
    def __init__(self, api_key: Optional[str] = None):
        self.parser = None
        self.analyzer = None
        self.ai_engine = AIReviewEngine(api_key)
    
    def review_code(self, code: str) -> Dict:
        """์ „์ฒด ์ฝ”๋“œ ๋ฆฌ๋ทฐ ํ”„๋กœ์„ธ์Šค ์‹คํ–‰"""
        
        print("=" * 60)
        print("๐ŸŽฏ ์ฝ”๋“œ ๋ฆฌ๋ทฐ ์‹œ์ž‘!")
        print("=" * 60)
        
        # 1. ์ฝ”๋“œ ํŒŒ์‹ฑ
        print("\n๐Ÿ“ 1๋‹จ๊ณ„: ์ฝ”๋“œ ํŒŒ์‹ฑ...")
        self.parser = CodeParser(code)
        if not self.parser.parse():
            return {'success': False, 'error': '์ฝ”๋“œ ํŒŒ์‹ฑ ์‹คํŒจ'}
        
        metrics = self.parser.extract_metrics()
        print(f"โœ… ํŒŒ์‹ฑ ์™„๋ฃŒ: {metrics.code_lines}์ค„์˜ ์ฝ”๋“œ ๋ถ„์„")
        
        # 2. ์ •์  ๋ถ„์„
        print("\n๐Ÿ” 2๋‹จ๊ณ„: ์ •์  ๋ถ„์„...")
        self.analyzer = StaticAnalyzer(code)
        issues = self.analyzer.run_all_checks(self.parser)
        print(f"โœ… ๋ถ„์„ ์™„๋ฃŒ: {len(issues)}๊ฐœ์˜ ์ด์Šˆ ๋ฐœ๊ฒฌ")
        
        # 3. AI ๋ฆฌ๋ทฐ
        print("\n๐Ÿค– 3๋‹จ๊ณ„: AI ๋ฆฌ๋ทฐ ์ƒ์„ฑ...")
        metrics_dict = {
            'total_lines': metrics.total_lines,
            'code_lines': metrics.code_lines,
            'functions': metrics.functions,
            'classes': metrics.classes,
            'complexity_score': metrics.complexity_score
        }
        
        ai_review = self.ai_engine.get_review(code, metrics_dict, issues)
        
        if ai_review['success']:
            print(f"โœ… AI ๋ฆฌ๋ทฐ ์™„๋ฃŒ (ํ† ํฐ ์‚ฌ์šฉ: {ai_review['tokens_used']})")
        else:
            print(f"โŒ AI ๋ฆฌ๋ทฐ ์‹คํŒจ: {ai_review['error']}")
        
        # 4. ๊ฒฐ๊ณผ ํ†ตํ•ฉ
        return {
            'success': True,
            'metrics': metrics_dict,
            'issues': issues,
            'ai_review': ai_review.get('review', ''),
            'tokens_used': ai_review.get('tokens_used', 0)
        }

# ์‚ฌ์šฉ ์˜ˆ์‹œ
if __name__ == "__main__":
    sample_code = """
def process_data(data):
    result = []
    for item in data:
        if item > 0:
            result.append(item * 2)
    return result

class UserManager:
    def __init__(self):
        self.users = []
    
    def add_user(self, user):
        self.users.append(user)
"""
    
    # API ํ‚ค๋Š” ํ™˜๊ฒฝ๋ณ€์ˆ˜์—์„œ ์ž๋™์œผ๋กœ ๋กœ๋“œ๋จ
    assistant = SmartReviewAssistant()
    review_result = assistant.review_code(sample_code)
    
    if review_result['success']:
        print("\n" + "=" * 60)
        print("๐Ÿ“Š ๋ฆฌ๋ทฐ ๊ฒฐ๊ณผ")
        print("=" * 60)
        print(review_result['ai_review'])

๐Ÿ’ฐ ๋น„์šฉ ๊ด€๋ฆฌ ํŒ: OpenAI API๋Š” ์‚ฌ์šฉํ•œ ํ† ํฐ๋งŒํผ ๋น„์šฉ์ด ๋ฐœ์ƒํ•ด์š”. GPT-4๋Š” ๋น„์‹ธ๋‹ˆ๊นŒ ๊ฐœ๋ฐœ ์ค‘์—๋Š” GPT-3.5-turbo๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ์ตœ์ข… ๋ฆฌ๋ทฐ์—๋งŒ GPT-4๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์€ ์ „๋žต์ด์—์š”. ๋˜ํ•œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์œ ์ง€ํ•˜๋ฉด ํ† ํฐ์„ ์ ˆ์•ฝํ•  ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค! ๐Ÿ’ธ

๐Ÿ“„ 4๋‹จ๊ณ„: ๋ฆฌํฌํŠธ ์ƒ์„ฑ๊ธฐ ๋งŒ๋“ค๊ธฐ

์ด์ œ ๋ฆฌ๋ทฐ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๊ธฐ ์ข‹๊ฒŒ ์ •๋ฆฌํ•ด์„œ ๋ณด์—ฌ์ฃผ๋Š” ๋ฆฌํฌํŠธ ์ƒ์„ฑ๊ธฐ๋ฅผ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค!

from datetime import datetime
from typing import Dict, List
import markdown
import os

class ReportGenerator:
    """์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋ฆฌํฌํŠธ ์ƒ์„ฑ๊ธฐ"""
    
    def __init__(self):
        self.template = None
    
    def generate_markdown_report(self, review_result: Dict, filename: str = "code_review_report.md") -> str:
        """๋งˆํฌ๋‹ค์šด ํ˜•์‹์˜ ๋ฆฌํฌํŠธ ์ƒ์„ฑ"""
        
        metrics = review_result['metrics']
        issues = review_result['issues']
        ai_review = review_result['ai_review']
        
        # ์ด์Šˆ ํ†ต๊ณ„
        error_count = sum(1 for i in issues if i.severity == 'error')
        warning_count = sum(1 for i in issues if i.severity == 'warning')
        info_count = sum(1 for i in issues if i.severity == 'info')
        
        report = f"""# ๐ŸŽฏ ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋ฆฌํฌํŠธ

**์ƒ์„ฑ ์‹œ๊ฐ„**: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}

---

## ๐Ÿ“Š ์ฝ”๋“œ ๋ฉ”ํŠธ๋ฆญ

| ํ•ญ๋ชฉ | ๊ฐ’ |
|------|-----|
| ์ „์ฒด ๋ผ์ธ ์ˆ˜ | {metrics['total_lines']} |
| ์ฝ”๋“œ ๋ผ์ธ ์ˆ˜ | {metrics['code_lines']} |
| ํ•จ์ˆ˜ ๊ฐœ์ˆ˜ | {len(metrics['functions'])} |
| ํด๋ž˜์Šค ๊ฐœ์ˆ˜ | {len(metrics['classes'])} |
| ๋ณต์žก๋„ ์ ์ˆ˜ | {metrics['complexity_score']:.1f} |

### ๋ฐœ๊ฒฌ๋œ ํ•จ์ˆ˜๋“ค
{', '.join([f'`{f}`' for f in metrics['functions']]) if metrics['functions'] else '์—†์Œ'}

### ๋ฐœ๊ฒฌ๋œ ํด๋ž˜์Šค๋“ค
{', '.join([f'`{c}`' for c in metrics['classes']]) if metrics['classes'] else '์—†์Œ'}

---

## ๐Ÿ” ์ •์  ๋ถ„์„ ๊ฒฐ๊ณผ

**์ด {len(issues)}๊ฐœ์˜ ์ด์Šˆ ๋ฐœ๊ฒฌ**
- ๐Ÿ”ด ์—๋Ÿฌ: {error_count}๊ฐœ
- ๐ŸŸก ๊ฒฝ๊ณ : {warning_count}๊ฐœ
- ๐Ÿ”ต ์ •๋ณด: {info_count}๊ฐœ

### ์ƒ์„ธ ์ด์Šˆ ๋ชฉ๋ก

"""
        
        # ์ด์Šˆ ์ƒ์„ธ ๋‚ด์—ญ
        for issue in issues:
            emoji = {'error': '๐Ÿ”ด', 'warning': '๐ŸŸก', 'info': '๐Ÿ”ต'}[issue.severity]
            report += f"""
#### {emoji} {issue.severity.upper()} - Line {issue.line}
- **๋ฉ”์‹œ์ง€**: {issue.message}
- **๊ทœ์น™**: `{issue.rule}`
- **์นดํ…Œ๊ณ ๋ฆฌ**: {issue.category}

"""
        
        # AI ๋ฆฌ๋ทฐ
        report += f"""
---

## ๐Ÿค– AI ์ฝ”๋“œ ๋ฆฌ๋ทฐ

{ai_review}

---

## ๐Ÿ“Œ ๋‹ค์Œ ๋‹จ๊ณ„

1. ๐Ÿ”ด ์—๋Ÿฌ ์ˆ˜์ค€์˜ ์ด์Šˆ๋ถ€ํ„ฐ ํ•ด๊ฒฐํ•˜์„ธ์š”
2. ๐ŸŸก ๊ฒฝ๊ณ  ์ˆ˜์ค€์˜ ์ด์Šˆ๋ฅผ ๊ฒ€ํ† ํ•˜์„ธ์š”
3. ๐Ÿ’ก AI ์ œ์•ˆ์‚ฌํ•ญ์„ ์ฐธ๊ณ ํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ๊ฐœ์„ ํ•˜์„ธ์š”
4. โœ… ๊ฐœ์„  ํ›„ ๋‹ค์‹œ ๋ฆฌ๋ทฐ๋ฅผ ์‹คํ–‰ํ•˜์„ธ์š”

---

*์ด ๋ฆฌํฌํŠธ๋Š” AI ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋„์šฐ๋ฏธ์— ์˜ํ•ด ์ž๋™ ์ƒ์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.*
"""
        
        # ํŒŒ์ผ๋กœ ์ €์žฅ
        with open(filename, 'w', encoding='utf-8') as f:
            f.write(report)
        
        print(f"๐Ÿ“„ ๋ฆฌํฌํŠธ๊ฐ€ '{filename}'์— ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")
        return report
    
    def generate_html_report(self, review_result: Dict, filename: str = "code_review_report.html") -> str:
        """HTML ํ˜•์‹์˜ ๋ฆฌํฌํŠธ ์ƒ์„ฑ"""
        
        # ๋จผ์ € ๋งˆํฌ๋‹ค์šด ์ƒ์„ฑ
        md_report = self.generate_markdown_report(review_result, "temp.md")
        
        # ๋งˆํฌ๋‹ค์šด์„ HTML๋กœ ๋ณ€ํ™˜
        html_content = markdown.markdown(md_report, extensions=['tables', 'fenced_code'])
        
        # HTML ํ…œํ”Œ๋ฆฟ
        html_template = f"""
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋ฆฌํฌํŠธ</title>
    <style>.tx-header{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);
color:#fff;
padding:40px 30px;
border-radius:16px;
text-align:center;
margin-bottom:40px;
box-shadow:0 8px 24px rgba(102,126,234,0.25);}
.tx-intro{background:#f8f9fa;
padding:25px;
border-radius:12px;
margin:30px 0;
border-left:5px solid #667eea;}
.tx-section{margin:40px 0;}
.tx-highlight{background:linear-gradient(120deg,#fef3c7 0%,#fde68a 100%);
padding:3px 8px;
border-radius:4px;
font-weight:600;}
.tx-box{background:#ffffff;
border:2px solid #e5e7eb;
padding:20px;
border-radius:12px;
margin:25px 0;
box-shadow:0 2px 8px rgba(0,0,0,0.05);}
.tx-tip{background:#ecfdf5;
border-left:4px solid #10b981;
padding:18px;
margin:25px 0;
border-radius:8px;}
.tx-warning{background:#fef2f2;
border-left:4px solid #ef4444;
padding:18px;
margin:25px 0;
border-radius:8px;}
.tx-step{background:#f0f9ff;
border-left:4px solid #3b82f6;
padding:18px;
margin:25px 0;
border-radius:8px;}
.tx-table{width:100%;
border-collapse:collapse;
margin:25px 0;}
.tx-table th{background:#667eea;
color:#fff;
padding:12px;
text-align:left;
font-weight:600;}
.tx-table td{padding:12px;
border-bottom:1px solid #e5e7eb;}
.tx-table tr:hover{background:#f9fafb;}
.tx-badge{display:inline-block;
background:#8b5cf6;
color:#fff;
padding:4px 12px;
border-radius:20px;
font-size:0.85em;
margin:5px;}
.tx-svg-container{text-align:center;
margin:40px 0;}</style>
</head>
<body>
    <div class="container">
        {html_content}
    </div>
</body>
</html>
"""
        
        # HTML ํŒŒ์ผ๋กœ ์ €์žฅ
        with open(filename, 'w', encoding='utf-8') as f:
            f.write(html_template)
        
        # ์ž„์‹œ ๋งˆํฌ๋‹ค์šด ํŒŒ์ผ ์‚ญ์ œ
        if os.path.exists("temp.md"):
            os.remove("temp.md")
        
        print(f"๐ŸŒ HTML ๋ฆฌํฌํŠธ๊ฐ€ '{filename}'์— ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!")
        return html_template
    
    def generate_summary(self, review_result: Dict) -> str:
        """๊ฐ„๋‹จํ•œ ์š”์•ฝ ์ƒ์„ฑ"""
        
        metrics = review_result['metrics']
        issues = review_result['issues']
        
        error_count = sum(1 for i in issues if i.severity == 'error')
        warning_count = sum(1 for i in issues if i.severity == 'warning')
        
        summary = f"""
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘        ๐Ÿ“Š ์ฝ”๋“œ ๋ฆฌ๋ทฐ ์š”์•ฝ                  โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

๐Ÿ“ ์ฝ”๋“œ ๋ผ์ธ: {metrics['code_lines']}์ค„
๐Ÿ”ง ํ•จ์ˆ˜: {len(metrics['functions'])}๊ฐœ
๐Ÿ“ฆ ํด๋ž˜์Šค: {len(metrics['classes'])}๊ฐœ
๐Ÿ“ˆ ๋ณต์žก๋„: {metrics['complexity_score']:.1f}

๐Ÿ” ๋ฐœ๊ฒฌ๋œ ์ด์Šˆ:
  ๐Ÿ”ด ์—๋Ÿฌ: {error_count}๊ฐœ
  ๐ŸŸก ๊ฒฝ๊ณ : {warning_count}๊ฐœ
  ๐Ÿ”ต ์ •๋ณด: {len(issues) - error_count - warning_count}๊ฐœ

{'โœ… ์ฝ”๋“œ ํ’ˆ์งˆ์ด ์šฐ์ˆ˜ํ•ฉ๋‹ˆ๋‹ค!' if error_count == 0 and warning_count == 0 else '๐Ÿ”ง ๊ฐœ์„ ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.'}
"""
        return summary

# ์‚ฌ์šฉ ์˜ˆ์‹œ
if __name__ == "__main__":
    # ๊ฐ€์ƒ์˜ ๋ฆฌ๋ทฐ ๊ฒฐ๊ณผ
    sample_result = {
        'metrics': {
            'total_lines': 50,
            'code_lines': 35,
            'functions': ['calculate_sum', 'process_data'],
            'classes': ['DataProcessor'],
            'complexity_score': 8.5
        },
        'issues': [
            CodeIssue('error', 10, 0, '๋ณ€์ˆ˜๊ฐ€ ์ •์˜๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค', 'undefined-variable', 'error'),
            CodeIssue('warning', 15, 0, 'ํ•จ์ˆ˜๊ฐ€ ๋„ˆ๋ฌด ๊น๋‹ˆ๋‹ค', 'function-too-long', 'style')
        ],
        'ai_review': '์ „๋ฐ˜์ ์œผ๋กœ ์ฝ”๋“œ ๊ตฌ์กฐ๊ฐ€ ์ข‹์Šต๋‹ˆ๋‹ค. ๋‹ค๋งŒ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.'
    }
    
    generator = ReportGenerator()
    
    # ์š”์•ฝ ์ถœ๋ ฅ
    print(generator.generate_summary(sample_result))
    
    # ๋งˆํฌ๋‹ค์šด ๋ฆฌํฌํŠธ ์ƒ์„ฑ
    generator.generate_markdown_report(sample_result)
    
    # HTML ๋ฆฌํฌํŠธ ์ƒ์„ฑ
    generator.generate_html_report(sample_result)

๐Ÿ–ฅ๏ธ 5๋‹จ๊ณ„: ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์ถ•ํ•˜๊ธฐ

์ด์ œ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ํ†ตํ•ฉํ•ด์„œ ์‹ค์ œ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“ค์–ด๋ด…์‹œ๋‹ค. CLI์™€ ๊ฐ„๋‹จํ•œ ์›น ์ธํ„ฐํŽ˜์ด์Šค ๋‘ ๊ฐ€์ง€๋ฅผ ๋งŒ๋“ค์–ด๋ณผ๊ฒŒ์š”!

CLI (Command Line Interface) ๋ฒ„์ „

import argparse
import sys
from pathlib import Path

class CodeReviewCLI:
    """๋ช…๋ น์ค„ ์ธํ„ฐํŽ˜์ด์Šค"""
    
    def __init__(self):
        self.assistant = None
        self.report_generator = ReportGenerator()
    
    def setup_argparse(self):
        """๋ช…๋ น์ค„ ์ธ์ž ํŒŒ์„œ ์„ค์ •"""
        parser = argparse.ArgumentParser(
            description='๐Ÿค– AI ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋„์šฐ๋ฏธ',
            formatter_class=argparse.RawDescriptionHelpFormatter,
            epilog="""
์‚ฌ์šฉ ์˜ˆ์‹œ:
  python cli.py review mycode.py
  python cli.py review mycode.py --output html
  python cli.py review mycode.py --model gpt-4
            """
        )
        
        subparsers = parser.add_subparsers(dest='command', help='๋ช…๋ น์–ด')
        
        # review ๋ช…๋ น์–ด
        review_parser = subparsers.add_parser('review', help='์ฝ”๋“œ ๋ฆฌ๋ทฐ ์‹คํ–‰')
        review_parser.add_argument('file', help='๋ฆฌ๋ทฐํ•  ํŒŒ์ด์ฌ ํŒŒ์ผ')
        review_parser.add_argument('--output', choices=['markdown', 'html', 'both'], 
                                  default='markdown', help='์ถœ๋ ฅ ํ˜•์‹')
        review_parser.add_argument('--model', default='gpt-3.5-turbo', 
                                  help='์‚ฌ์šฉํ•  AI ๋ชจ๋ธ')
        review_parser.add_argument('--no-ai', action='store_true', 
                                  help='AI ๋ฆฌ๋ทฐ ์—†์ด ์ •์  ๋ถ„์„๋งŒ ์‹คํ–‰')
        
        # explain ๋ช…๋ น์–ด
        explain_parser = subparsers.add_parser('explain', help='๊ฐœ๋… ์„ค๋ช…')
        explain_parser.add_argument('concept', help='์„ค๋ช…ํ•  ๊ฐœ๋…')
        
        return parser
    
    def run_review(self, args):
        """๋ฆฌ๋ทฐ ์‹คํ–‰"""
        
        # ํŒŒ์ผ ์ฝ๊ธฐ
        file_path = Path(args.file)
        if not file_path.exists():
            print(f"โŒ ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: {args.file}")
            return
        
        with open(file_path, 'r', encoding='utf-8') as f:
            code = f.read()
        
        print(f"\n๐ŸŽฏ '{args.file}' ๋ฆฌ๋ทฐ ์‹œ์ž‘...\n")
        
        # ์–ด์‹œ์Šคํ„ดํŠธ ์ดˆ๊ธฐํ™”
        if args.no_ai:
            # AI ์—†์ด ์ •์  ๋ถ„์„๋งŒ
            parser = CodeParser(code)
            parser.parse()
            metrics = parser.extract_metrics()
            
            analyzer = StaticAnalyzer(code)
            issues = analyzer.run_all_checks(parser)
            
            review_result = {
                'metrics': {
                    'total_lines': metrics.total_lines,
                    'code_lines': metrics.code_lines,
                    'functions': metrics.functions,
                    'classes': metrics.classes,
                    'complexity_score': metrics.complexity_score
                },
                'issues': issues,
                'ai_review': 'AI ๋ฆฌ๋ทฐ๊ฐ€ ๋น„ํ™œ์„ฑํ™”๋˜์—ˆ์Šต๋‹ˆ๋‹ค.'
            }
        else:
            # ์ „์ฒด ๋ฆฌ๋ทฐ
            self.assistant = SmartReviewAssistant()
            review_result = self.assistant.review_code(code)
        
        # ์š”์•ฝ ์ถœ๋ ฅ
        print("\n" + self.report_generator.generate_summary(review_result))
        
        # ๋ฆฌํฌํŠธ ์ƒ์„ฑ
        base_name = file_path.stem
        
        if args.output in ['markdown', 'both']:
            self.report_generator.generate_markdown_report(
                review_result, 
                f"{base_name}_review.md"
            )
        
        if args.output in ['html', 'both']:
            self.report_generator.generate_html_report(
                review_result, 
                f"{base_name}_review.html"
            )
        
        print("\nโœ… ๋ฆฌ๋ทฐ ์™„๋ฃŒ!")
    
    def run_explain(self, args):
        """๊ฐœ๋… ์„ค๋ช…"""
        
        if not self.assistant:
            self.assistant = SmartReviewAssistant()
        
        print(f"\n๐Ÿ’ก '{args.concept}' ์„ค๋ช…:\n")
        explanation = self.assistant.ai_engine.explain_concept(args.concept)
        print(explanation)
    
    def run(self):
        """CLI ์‹คํ–‰"""
        parser = self.setup_argparse()
        args = parser.parse_args()
        
        if not args.command:
            parser.print_help()
            return
        
        if args.command == 'review':
            self.run_review(args)
        elif args.command == 'explain':
            self.run_explain(args)

if __name__ == "__main__":
    cli = CodeReviewCLI()
    cli.run()

์›น ์ธํ„ฐํŽ˜์ด์Šค (Flask) ๋ฒ„์ „

from flask import Flask, render_template_string, request, jsonify
import json

app = Flask(__name__)

# HTML ํ…œํ”Œ๋ฆฟ
HTML_TEMPLATE = """
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>๐Ÿค– AI ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋„์šฐ๋ฏธ</title>
    <style>.tx-header{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);
color:#fff;
padding:40px 30px;
border-radius:16px;
text-align:center;
margin-bottom:40px;
box-shadow:0 8px 24px rgba(102,126,234,0.25);}
.tx-intro{background:#f8f9fa;
padding:25px;
border-radius:12px;
margin:30px 0;
border-left:5px solid #667eea;}
.tx-section{margin:40px 0;}
.tx-highlight{background:linear-gradient(120deg,#fef3c7 0%,#fde68a 100%);
padding:3px 8px;
border-radius:4px;
font-weight:600;}
.tx-box{background:#ffffff;
border:2px solid #e5e7eb;
padding:20px;
border-radius:12px;
margin:25px 0;
box-shadow:0 2px 8px rgba(0,0,0,0.05);}
.tx-tip{background:#ecfdf5;
border-left:4px solid #10b981;
padding:18px;
margin:25px 0;
border-radius:8px;}
.tx-warning{background:#fef2f2;
border-left:4px solid #ef4444;
padding:18px;
margin:25px 0;
border-radius:8px;}
.tx-step{background:#f0f9ff;
border-left:4px solid #3b82f6;
padding:18px;
margin:25px 0;
border-radius:8px;}
.tx-table{width:100%;
border-collapse:collapse;
margin:25px 0;}
.tx-table th{background:#667eea;
color:#fff;
padding:12px;
text-align:left;
font-weight:600;}
.tx-table td{padding:12px;
border-bottom:1px solid #e5e7eb;}
.tx-table tr:hover{background:#f9fafb;}
.tx-badge{display:inline-block;
background:#8b5cf6;
color:#fff;
padding:4px 12px;
border-radius:20px;
font-size:0.85em;
margin:5px;}
.tx-svg-container{text-align:center;
margin:40px 0;}</style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>๐Ÿค– AI ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋„์šฐ๋ฏธ</h1>
            <p>ํŒŒ์ด์ฌ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด AI๊ฐ€ ๋ฆฌ๋ทฐํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค!</p>
        </div>
        
        <div class="content">
            <div class="editor-section">
                <div>
                    <h3>๐Ÿ“ ์ฝ”๋“œ ์ž…๋ ฅ</h3>
                    <textarea id="codeInput" placeholder="์—ฌ๊ธฐ์— ํŒŒ์ด์ฌ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...">def hello_world():
    print("Hello, World!")

hello_world()</textarea>
                </div>
                <div>
                    <h3>โ„น๏ธ ์„ค์ •</h3>
                    <div style="padding: 15px;">
                        <label>
                            <input type="checkbox" id="useAI" checked>
                            AI ๋ฆฌ๋ทฐ ์‚ฌ์šฉ
                        </label>
                        <br><br>
                        <label>
                            AI ๋ชจ๋ธ:
                            <select id="modelSelect">
                                <option value="gpt-3.5-turbo">GPT-3.5 Turbo (๋น ๋ฆ„)</option>
                                <option value="gpt-4">GPT-4 (์ •ํ™•ํ•จ)</option>
                            </select>
                        </label>
                    </div>
                </div>
            </div>
            
            <div class="button-group">
                <button class="btn-primary" onclick="reviewCode()">
                    ๐Ÿš€ ๋ฆฌ๋ทฐ ์‹œ์ž‘
                </button>
                <button class="btn-secondary" onclick="clearAll()">
                    ๐Ÿ—‘๏ธ ์ดˆ๊ธฐํ™”
                </button>
            </div>
            
            <div class="loading" id="loading">
                <div class="spinner"></div>
                <p style="margin-top: 20px;">AI๊ฐ€ ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค...</p>
            </div>
            
            <div class="result-section" id="resultSection">
                <h2>๐Ÿ“Š ๋ฆฌ๋ทฐ ๊ฒฐ๊ณผ</h2>
                <div id="resultContent"></div>
            </div>
        </div>
    </div>
    
    <script>
        async function reviewCode() {
            const code = document.getElementById('codeInput').value;
            const useAI = document.getElementById('useAI').checked;
            const model = document.getElementById('modelSelect').value;
            
            if (!code.trim()) {
                alert('์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!');
                return;
            }
            
            // ๋กœ๋”ฉ ํ‘œ์‹œ
            document.getElementById('loading').classList.add('show');
            document.getElementById('resultSection').classList.remove('show');
            
            try {
                const response = await fetch('/api/review', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        code: code,
                        use_ai: useAI,
                        model: model
                    })
                });
                
                const result = await response.json();
                
                // ๊ฒฐ๊ณผ ํ‘œ์‹œ
                displayResult(result);
                
            } catch (error) {
                alert('๋ฆฌ๋ทฐ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: ' + error.message);
            } finally {
                document.getElementById('loading').classList.remove('show');
            }
        }
        
        function displayResult(result) {
            const resultContent = document.getElementById('resultContent');
            const metrics = result.metrics;
            const issues = result.issues;
            
            let html = `
                <div class="metric-card">
                    <h3>๐Ÿ“ˆ ์ฝ”๋“œ ๋ฉ”ํŠธ๋ฆญ</h3>
                    <p>์ „์ฒด ๋ผ์ธ: ${metrics.total_lines} | ์ฝ”๋“œ ๋ผ์ธ: ${metrics.code_lines}</p>
                    <p>ํ•จ์ˆ˜: ${metrics.functions.length}๊ฐœ | ํด๋ž˜์Šค: ${metrics.classes.length}๊ฐœ</p>
                    <p>๋ณต์žก๋„: ${metrics.complexity_score.toFixed(1)}</p>
                </div>
                
                <div class="metric-card">
                    <h3>๐Ÿ” ๋ฐœ๊ฒฌ๋œ ์ด์Šˆ (${issues.length}๊ฐœ)</h3>
            `;
            
            issues.forEach(issue => {
                html += `
                    <div class="issue-item ${issue.severity}">
                        <strong>${issue.severity.toUpperCase()}</strong> - Line ${issue.line}<br>
                        ${issue.message}
                    </div>
                `;
            });
            
            html += `</div>`;
            
            if (result.ai_review) {
                html += `
                    <div class="metric-card">
                        <h3>๐Ÿค– AI ๋ฆฌ๋ทฐ</h3>
                        <pre style="white-space: pre-wrap;">${result.ai_review}</pre>
                    </div>
                `;
            }
            
            resultContent.innerHTML = html;
            document.getElementById('resultSection').classList.add('show');
        }
        
        function clearAll() {
            document.getElementById('codeInput').value = '';
            document.getElementById('resultSection').classList.remove('show');
        }
    </script>
</body>
</html>
"""

@app.route('/')
def index():
    return render_template_string(HTML_TEMPLATE)

@app.route('/api/review', methods=['POST'])
def api_review():
    data = request.json
    code = data.get('code', '')
    use_ai = data.get('use_ai', True)
    model = data.get('model', 'gpt-3.5-turbo')
    
    try:
        # ์ฝ”๋“œ ๋ฆฌ๋ทฐ ์‹คํ–‰
        assistant = SmartReviewAssistant()
        result = assistant.review_code(code)
        
        # JSON ์ง๋ ฌํ™” ๊ฐ€๋Šฅํ•œ ํ˜•ํƒœ๋กœ ๋ณ€ํ™˜
        response = {
            'success': True,
            'metrics': result['metrics'],
            'issues': [
                {
                    'severity': issue.severity,
                    'line': issue.line,
                    'message': issue.message,
                    'rule': issue.rule
                }
                for issue in result['issues']
            ],
            'ai_review': result.get('ai_review', '')
        }
        
        return jsonify(response)
        
    except Exception as e:
        return jsonify({
            'success': False,
            'error': str(e)
        }), 500

if __name__ == '__main__':
    print("๐Ÿš€ ์›น ์„œ๋ฒ„ ์‹œ์ž‘!")
    print("๐Ÿ‘‰ ๋ธŒ๋ผ์šฐ์ €์—์„œ http://localhost:5000 ์„ ์—ด์–ด๋ณด์„ธ์š”!")
    app.run(debug=True, port=5000)

๐ŸŒ ์›น ๋ฒ„์ „ ์‹คํ–‰ํ•˜๊ธฐ: ์œ„ ์ฝ”๋“œ๋ฅผ app.py๋กœ ์ €์žฅํ•˜๊ณ  python app.py๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์›น ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”! ํŠนํžˆ ์žฌ๋Šฅ๋„ท์—์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ฐ•์˜๋ฅผ ํ•˜์‹œ๋Š” ๋ถ„๋“ค์€ ์ด ์›น ๋ฒ„์ „์„ ํ•™์ƒ๋“ค์—๊ฒŒ ์ œ๊ณตํ•˜๋ฉด ์ •๋ง ์œ ์šฉํ•  ๊ฑฐ์˜ˆ์š”! ๐ŸŽ“

๐ŸŽจ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ ์ถ”๊ฐ€ํ•˜๊ธฐ

๊ธฐ๋ณธ ๊ธฐ๋Šฅ์€ ์™„์„ฑํ–ˆ์œผ๋‹ˆ, ์ด์ œ ๋” ๋ฉ‹์ง„ ๊ธฐ๋Šฅ๋“ค์„ ์ถ”๊ฐ€ํ•ด๋ด…์‹œ๋‹ค!

1. Git ํ†ตํ•ฉ ๊ธฐ๋Šฅ

import git
from typing import List, Dict

class GitIntegration:
    """Git๊ณผ ํ†ตํ•ฉํ•˜์—ฌ ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ๋งŒ ๋ฆฌ๋ทฐ"""
    
    def __init__(self, repo_path: str = "."):
        try:
            self.repo = git.Repo(repo_path)
        except:
            raise ValueError("Git ์ €์žฅ์†Œ๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค!")
    
    def get_changed_files(self, branch: str = "HEAD") -> List[str]:
        """๋ณ€๊ฒฝ๋œ ํŒŒ์ด์ฌ ํŒŒ์ผ ๋ชฉ๋ก ๊ฐ€์ ธ์˜ค๊ธฐ"""
        
        changed_files = []
        
        # ์Šคํ…Œ์ด์ง•๋œ ํŒŒ์ผ
        for item in self.repo.index.diff("HEAD"):
            if item.a_path.endswith('.py'):
                changed_files.append(item.a_path)
        
        # ์Šคํ…Œ์ด์ง•๋˜์ง€ ์•Š์€ ํŒŒ์ผ
        for item in self.repo.index.diff(None):
            if item.a_path.endswith('.py'):
                changed_files.append(item.a_path)
        
        return list(set(changed_files))
    
    def get_file_diff(self, filepath: str) -> str:
        """ํŒŒ์ผ์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ ๊ฐ€์ ธ์˜ค๊ธฐ"""
        
        try:
            diff = self.repo.git.diff('HEAD', filepath)
            return diff
        except:
            return ""
    
    def review_commit(self, commit_hash: str = "HEAD") -> Dict:
        """ํŠน์ • ์ปค๋ฐ‹์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ ๋ฆฌ๋ทฐ"""
        
        commit = self.repo.commit(commit_hash)
        
        results = {
            'commit': commit_hash,
            'message': commit.message,
            'author': str(commit.author),
            'files_reviewed': []
        }
        
        for item in commit.stats.files:
            if item.endswith('.py'):
                # ํŒŒ์ผ ๋‚ด์šฉ ๊ฐ€์ ธ์˜ค๊ธฐ
                file_content = (commit.tree / item).data_stream.read().decode('utf-8')
                
                # ๋ฆฌ๋ทฐ ์‹คํ–‰
                assistant = SmartReviewAssistant()
                review = assistant.review_code(file_content)
                
                results['files_reviewed'].append({
                    'file': item,
                    'review': review
                })
        
        return results

# ์‚ฌ์šฉ ์˜ˆ์‹œ
if __name__ == "__main__":
    git_integration = GitIntegration()
    
    # ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ ํ™•์ธ
    changed_files = git_integration.get_changed_files()
    print(f"๐Ÿ“ ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ: {changed_files}")
    
    # ๊ฐ ํŒŒ์ผ ๋ฆฌ๋ทฐ
    for filepath in changed_files:
        print(f"\n๐Ÿ” {filepath} ๋ฆฌ๋ทฐ ์ค‘...")
        with open(filepath, 'r') as f:
            code = f.read()
        
        assistant = SmartReviewAssistant()
        result = assistant.review_code(code)
        
        # ๋ฆฌํฌํŠธ ์ƒ์„ฑ
        generator = ReportGenerator()
        generator.generate_markdown_report(result, f"{filepath}_review.md")

2. ์ฝ”๋“œ ์ž๋™ ์ˆ˜์ • ๊ธฐ๋Šฅ

import black
import autopep8

class CodeFixer:
    """์ฝ”๋“œ ์ž๋™ ์ˆ˜์ • ๋„๊ตฌ"""
    
    def __init__(self, code: str):
        self.original_code = code
        self.fixed_code = code
    
    def apply_black(self) -> str:
        """Black ํฌ๋งทํ„ฐ ์ ์šฉ"""
        try:
            self.fixed_code = black.format_str(
                self.fixed_code,
                mode=black.FileMode()
            )
            print("โœ… Black ํฌ๋งทํŒ… ์™„๋ฃŒ")
        except Exception as e:
            print(f"โš ๏ธ Black ํฌ๋งทํŒ… ์‹คํŒจ: {e}")
        
        return self.fixed_code
    
    def apply_autopep8(self) -> str:
        """autopep8 ์ ์šฉ"""
        try:
            self.fixed_code = autopep8.fix_code(
                self.fixed_code,
                options={'aggressive': 1}
            )
            print("โœ… autopep8 ์ ์šฉ ์™„๋ฃŒ")
        except Exception as e:
            print(f"โš ๏ธ autopep8 ์ ์šฉ ์‹คํŒจ: {e}")
        
        return self.fixed_code
    
    def fix_common_issues(self) -> str:
        """์ผ๋ฐ˜์ ์ธ ์ด์Šˆ ์ž๋™ ์ˆ˜์ •"""
        
        lines = self.fixed_code.split('\n')
        fixed_lines = []
        
        for line in lines:
            # ํ›„ํ–‰ ๊ณต๋ฐฑ ์ œ๊ฑฐ
            line = line.rstrip()
            
            # ํƒญ์„ ์ŠคํŽ˜์ด์Šค๋กœ ๋ณ€ํ™˜
            line = line.replace('\t', '    ')
            
            fixed_lines.append(line)
        
        self.fixed_code = '\n'.join(fixed_lines)
        print("โœ… ์ผ๋ฐ˜ ์ด์Šˆ ์ˆ˜์ • ์™„๋ฃŒ")
        
        return self.fixed_code
    
    def get_diff(self) -> str:
        """์›๋ณธ๊ณผ ์ˆ˜์ •๋ณธ์˜ ์ฐจ์ด ๋ณด๊ธฐ"""
        import difflib
        
        diff = difflib.unified_diff(
            self.original_code.splitlines(keepends=True),
            self.fixed_code.splitlines(keepends=True),
            fromfile='original',
            tofile='fixed'
        )
        
        return ''.join(diff)
    
    def apply_all_fixes(self) -> str:
        """๋ชจ๋“  ์ˆ˜์ • ์ ์šฉ"""
        print("๐Ÿ”ง ์ฝ”๋“œ ์ž๋™ ์ˆ˜์ • ์‹œ์ž‘...\n")
        
        self.fix_common_issues()
        self.apply_autopep8()
        self.apply_black()
        
        print("\n๐Ÿ“Š ์ˆ˜์ • ์™„๋ฃŒ!")
        print(f"์›๋ณธ: {len(self.original_code)}์ž")
        print(f"์ˆ˜์ •: {len(self.fixed_code)}์ž")
        
        return self.fixed_code

# ์‚ฌ์šฉ ์˜ˆ์‹œ
if __name__ == "__main__":
    messy_code = """
def calculate(x,y):
  result=x+y
  return result

class myClass:
    def __init__(self):
        pass
"""
    
    fixer = CodeFixer(messy_code)
    fixed = fixer.apply_all_fixes()
    
    print("\n" + "="*50)
    print("์ˆ˜์ •๋œ ์ฝ”๋“œ:")
    print("="*50)
    print(fixed)
    
    print("\n" + "="*50)
    print("๋ณ€๊ฒฝ ์‚ฌํ•ญ:")
    print("="*50)
    print(fixer.get_diff())

3. ํ•™์Šต ๋ชจ๋“œ ๊ธฐ๋Šฅ

class LearningMode:
    """์ดˆ๋ณด์ž๋ฅผ ์œ„ํ•œ ํ•™์Šต ๋ชจ๋“œ"""
    
    def __init__(self, ai_engine):
        self.ai_engine = ai_engine
        self.learning_history = []
    
    def explain_issue(self, issue: CodeIssue) -> str:
        """์ด์Šˆ์— ๋Œ€ํ•œ ์ƒ์„ธ ์„ค๋ช…"""
        
        prompt = f"""
๋‹ค์Œ ์ฝ”๋“œ ์ด์Šˆ๋ฅผ ์ดˆ๋ณด์ž๋„ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๊ฒŒ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”:

์ด์Šˆ: {issue.message}
๊ทœ์น™: {issue.rule}

๋‹ค์Œ ๋‚ด์šฉ์„ ํฌํ•จํ•ด์ฃผ์„ธ์š”:
1. ์™œ ์ด๊ฒƒ์ด ๋ฌธ์ œ์ธ๊ฐ€?
2. ์–ด๋–ป๊ฒŒ ์ˆ˜์ •ํ•ด์•ผ ํ•˜๋Š”๊ฐ€?
3. ์‹ค์ œ ์˜ˆ์‹œ ์ฝ”๋“œ
4. ์ถ”๊ฐ€ ํ•™์Šต ์ž๋ฃŒ ์ถ”์ฒœ
"""
        
        explanation = self.ai_engine.explain_concept(prompt)
        
        self.learning_history.append({
            'issue': issue.message,
            'explanation': explanation
        })
        
        return explanation
    
    def suggest_practice(self, topic: str) -> str:
        """์—ฐ์Šต ๋ฌธ์ œ ์ œ์•ˆ"""
        
        prompt = f"""
'{topic}'์— ๋Œ€ํ•œ ํŒŒ์ด์ฌ ์—ฐ์Šต ๋ฌธ์ œ๋ฅผ 3๊ฐœ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”.
๋‚œ์ด๋„: ์ดˆ๊ธ‰, ์ค‘๊ธ‰, ๊ณ ๊ธ‰ ๊ฐ 1๊ฐœ์”ฉ

๊ฐ ๋ฌธ์ œ๋Š” ๋‹ค์Œ์„ ํฌํ•จํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค:
- ๋ฌธ์ œ ์„ค๋ช…
- ์ž…๋ ฅ/์ถœ๋ ฅ ์˜ˆ์‹œ
- ํžŒํŠธ
"""
        
        return self.ai_engine.explain_concept(prompt)
    
    def generate_study_plan(self, issues: List[CodeIssue]) -> str:
        """์ด์Šˆ ๊ธฐ๋ฐ˜ ํ•™์Šต ๊ณ„ํš ์ƒ์„ฑ"""
        
        issue_categories = {}
        for issue in issues:
            category = issue.category
            if category not in issue_categories:
                issue_categories[category] = []
            issue_categories[category].append(issue)
        
        plan = "๐Ÿ“š ๋งž์ถคํ˜• ํ•™์Šต ๊ณ„ํš\n\n"
        
        for i, (category, category_issues) in enumerate(issue_categories.items(), 1):
            plan += f"{i}. {category.upper()} ({len(category_issues)}๊ฐœ ์ด์Šˆ)\n"
            plan += f"   ์ถ”์ฒœ ํ•™์Šต ์‹œ๊ฐ„: {len(category_issues) * 30}๋ถ„\n"
            plan += f"   ์šฐ์„ ์ˆœ์œ„: {'๋†’์Œ' if len(category_issues) > 3 else '๋ณดํ†ต'}\n\n"
        
        return plan

# ์‚ฌ์šฉ ์˜ˆ์‹œ
if __name__ == "__main__":
    # AI ์—”์ง„ ์ดˆ๊ธฐํ™”
    ai_engine = AIReviewEngine()
    learning_mode = LearningMode(ai_engine)
    
    # ์ด์Šˆ ์„ค๋ช…
    sample_issue = CodeIssue(
        'warning',
        10,
        0,
        'ํ•จ์ˆ˜๊ฐ€ ๋„ˆ๋ฌด ๊น๋‹ˆ๋‹ค',
        'function-too-long',
        'maintainability'
    )
    
    explanation = learning_mode.explain_issue(sample_issue)
    print("๐Ÿ’ก ์ด์Šˆ ์„ค๋ช…:")
    print(explanation)
    
    # ์—ฐ์Šต ๋ฌธ์ œ ์ œ์•ˆ
    print("\n๐Ÿ“ ์—ฐ์Šต ๋ฌธ์ œ:")
    practice = learning_mode.suggest_practice("ํ•จ์ˆ˜ ๋ฆฌํŒฉํ† ๋ง")
    print(practice)

๐Ÿš€ ๋ฐฐํฌ ๋ฐ ์‹ค์ „ ํ™œ์šฉ

์ด์ œ ๋งŒ๋“  ๋„๊ตฌ๋ฅผ ์‹ค์ œ๋กœ ํ™œ์šฉํ•ด๋ด…์‹œ๋‹ค!

๐Ÿ“ฆ ํŒจํ‚ค์ง€ ๊ตฌ์กฐ:

code-review-ai/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ parser.py          # CodeParser ํด๋ž˜์Šค
โ”‚   โ”œโ”€โ”€ analyzer.py        # StaticAnalyzer ํด๋ž˜์Šค
โ”‚   โ”œโ”€โ”€ ai_engine.py       # AIReviewEngine ํด๋ž˜์Šค
โ”‚   โ”œโ”€โ”€ reporter.py        # ReportGenerator ํด๋ž˜์Šค
โ”‚   โ”œโ”€โ”€ fixer.py           # CodeFixer ํด๋ž˜์Šค
โ”‚   โ””โ”€โ”€ learning.py        # LearningMode ํด๋ž˜์Šค
โ”œโ”€โ”€ cli.py                 # CLI ์ธํ„ฐํŽ˜์ด์Šค
โ”œโ”€โ”€ app.py                 # ์›น ์ธํ„ฐํŽ˜์ด์Šค
โ”œโ”€โ”€ requirements.txt       # ์˜์กด์„ฑ ๋ชฉ๋ก
โ”œโ”€โ”€ .env.example          # ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์˜ˆ์‹œ
โ”œโ”€โ”€ README.md             # ์‚ฌ์šฉ ์„ค๋ช…์„œ
โ””โ”€โ”€ tests/                # ํ…Œ์ŠคํŠธ ์ฝ”๋“œ
    โ”œโ”€โ”€ test_parser.py
    โ”œโ”€โ”€ test_analyzer.py
    โ””โ”€โ”€ test_ai_engine.py

Docker๋กœ ๋ฐฐํฌํ•˜๊ธฐ

# Dockerfile
FROM python:3.11-slim

WORKDIR /app

# ์˜์กด์„ฑ ์„ค์น˜
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ณต์‚ฌ
COPY . .

# ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ •
ENV FLASK_APP=app.py
ENV FLASK_ENV=production

# ํฌํŠธ ๋…ธ์ถœ
EXPOSE 5000

# ์‹คํ–‰
CMD ["python", "app.py"]
# docker-compose.yml
version: '3.8'

services:
  web:
    build: .
    ports:
      - "5000:5000"
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY}
    volumes:
      - ./reports:/app/reports
    restart: unless-stopped

CI/CD ํ†ตํ•ฉ (GitHub Actions)

# .github/workflows/code-review.yml
name: AI Code Review

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v2
    
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.11'
    
    - name: Install dependencies
      run: |
        pip install -r requirements.txt
    
    - name: Run AI Code Review
      env:
        OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
      run: |
        python cli.py review $(git diff --name-only HEAD^..HEAD | grep '.py$')
    
    - name: Upload Review Report
      uses: actions/upload-artifact@v2
      with:
        name: review-report
        path: '*_review.md'
    
    - name: Comment on PR
      uses: actions/github-script@v5
      with:
        script: |
          const fs = require('fs');
          const report = fs.readFileSync('code_review_report.md', 'utf8');
          github.rest.issues.createComment({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            body: report
          });

๐Ÿ’ก ์‹ค์ „ ํ™œ์šฉ ํŒ๊ณผ ๋ฒ ์ŠคํŠธ ํ”„๋ž™ํ‹ฐ์Šค

1. API ๋น„์šฉ ์ตœ์ ํ™”

โ€ข ์บ์‹ฑ ํ™œ์šฉ: ๊ฐ™์€ ์ฝ”๋“œ๋Š” ๋‹ค์‹œ ๋ถ„์„ํ•˜์ง€ ์•Š๊ธฐ
โ€ข ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ: ์—ฌ๋Ÿฌ ํŒŒ์ผ์„ ํ•œ ๋ฒˆ์— ์ฒ˜๋ฆฌ
โ€ข ๋ชจ๋ธ ์„ ํƒ: ๊ฐ„๋‹จํ•œ ๋ฆฌ๋ทฐ๋Š” GPT-3.5, ๋ณต์žกํ•œ ๋ฆฌ๋ทฐ๋Š” GPT-4
โ€ข ํ”„๋กฌํ”„ํŠธ ์ตœ์ ํ™”: ๋ถˆํ•„์š”ํ•œ ๋‚ด์šฉ ์ œ๊ฑฐ

2. ํŒ€ ํ™˜๊ฒฝ์—์„œ ํ™œ์šฉํ•˜๊ธฐ

โ€ข ์ฝ”๋”ฉ ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ ํ†ตํ•ฉ
โ€ข ํŒ€ ๊ทœ์น™ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•
โ€ข ๋ฆฌ๋ทฐ ๊ธฐ์ค€ ์ผ๊ด€์„ฑ ์œ ์ง€
โ€ข ํ•™์Šต ์ž๋ฃŒ๋กœ ํ™œ์šฉ

3. ๊ต์œก ๋ชฉ์ ์œผ๋กœ ํ™œ์šฉํ•˜๊ธฐ

ํŠนํžˆ ์žฌ๋Šฅ๋„ท์—์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ๊ฐ€๋ฅด์น˜์‹œ๋Š” ๋ถ„๋“ค๊ป˜ ์œ ์šฉํ•œ ํŒ์ด์—์š”!

โ€ข ํ•™์ƒ ์ฝ”๋“œ ์ž๋™ ๋ฆฌ๋ทฐ
โ€ข ์ฆ‰๊ฐ์ ์ธ ํ”ผ๋“œ๋ฐฑ ์ œ๊ณต
โ€ข ํ•™์Šต ์ง„๋„ ์ถ”์ 
โ€ข ๋งž์ถคํ˜• ์—ฐ์Šต ๋ฌธ์ œ ์ƒ์„ฑ

โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ: 1. AI๋Š” ๋ณด์กฐ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. ์ตœ์ข… ํŒ๋‹จ์€ ์‚ฌ๋žŒ์ด ํ•ด์•ผ ํ•ด์š”
2. ๋ฏผ๊ฐํ•œ ์ฝ”๋“œ๋Š” ์™ธ๋ถ€ API๋กœ ๋ณด๋‚ด์ง€ ๋งˆ์„ธ์š”
3. ๋ผ์ด์„ ์Šค๋ฅผ ํ™•์ธํ•˜๊ณ  ์‚ฌ์šฉํ•˜์„ธ์š”
4. ๊ณผ๋„ํ•œ ์˜์กด์€ ํ•™์Šต์— ๋ฐฉํ•ด๊ฐ€ ๋  ์ˆ˜ ์žˆ์–ด์š”

๐ŸŽ“ ๋” ๋‚˜์•„๊ฐ€๊ธฐ: ๊ณ ๊ธ‰ ์ฃผ์ œ๋“ค

๊ธฐ๋ณธ ๊ธฐ๋Šฅ์„ ๋งˆ์Šคํ„ฐํ–ˆ๋‹ค๋ฉด, ์ด๋Ÿฐ ๊ณ ๊ธ‰ ๊ธฐ๋Šฅ๋“ค๋„ ๋„์ „ํ•ด๋ณด์„ธ์š”!

๐Ÿš€ ํ™•์žฅ ์•„์ด๋””์–ด: ๋‹ค๊ตญ์–ด ์ง€์› ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋„ ๋ฆฌ๋ทฐ
๋ณด์•ˆ ์Šค์บ” ์ทจ์•ฝ์  ์ž๋™ ํƒ์ง€
์„ฑ๋Šฅ ๋ถ„์„ ์‹คํ–‰ ์‹œ๊ฐ„ ํ”„๋กœํŒŒ์ผ๋ง
ํ…Œ์ŠคํŠธ ์ƒ์„ฑ ์ž๋™ ์œ ๋‹› ํ…Œ์ŠคํŠธ ์ž‘์„ฑ
๋ฌธ์„œํ™” ์ž๋™ docstring ์ƒ์„ฑ
๋ฆฌํŒฉํ† ๋ง ์ œ์•ˆ ๋””์ž์ธ ํŒจํ„ด ์ ์šฉ
ํ˜‘์—… ๊ธฐ๋Šฅ ํŒ€ ๋Œ€์‹œ๋ณด๋“œ ๊ตฌ์ถ•

์˜ˆ์‹œ: ์ž๋™ ํ…Œ์ŠคํŠธ ์ƒ์„ฑ๊ธฐ

class TestGenerator:
    """ํ•จ์ˆ˜์— ๋Œ€ํ•œ ์œ ๋‹› ํ…Œ์ŠคํŠธ ์ž๋™ ์ƒ์„ฑ"""
    
    def __init__(self, ai_engine):
        self.ai_engine = ai_engine
    
    def generate_tests(self, function_code: str, function_name: str) -> str:
        """ํ•จ์ˆ˜์— ๋Œ€ํ•œ pytest ํ…Œ์ŠคํŠธ ์ƒ์„ฑ"""
        
        prompt = f"""
๋‹ค์Œ ํŒŒ์ด์ฌ ํ•จ์ˆ˜์— ๋Œ€ํ•œ pytest ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”:

```python
{function_code}
```

๋‹ค์Œ์„ ํฌํ•จํ•ด์ฃผ์„ธ์š”:
1. ์ •์ƒ ์ผ€์ด์Šค ํ…Œ์ŠคํŠธ
2. ๊ฒฝ๊ณ„๊ฐ’ ํ…Œ์ŠคํŠธ
3. ์˜ˆ์™ธ ์ƒํ™ฉ ํ…Œ์ŠคํŠธ
4. ์ ์ ˆํ•œ assert ๋ฌธ
5. ํ…Œ์ŠคํŠธ ํ•จ์ˆ˜๋ช…์€ test_{function_name}_๋กœ ์‹œ์ž‘

์™„์ „ํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋งŒ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
"""
        
        response = self.ai_engine.explain_concept(prompt)
        return response

# ์‚ฌ์šฉ ์˜ˆ์‹œ
if __name__ == "__main__":
    function_code = """
def divide(a, b):
    '''๋‘ ์ˆซ์ž๋ฅผ ๋‚˜๋ˆ•๋‹ˆ๋‹ค'''
    if b == 0:
        raise ValueError("0์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค")
    return a / b
"""
    
    ai_engine = AIReviewEngine()
    test_gen = TestGenerator(ai_engine)
    
    tests = test_gen.generate_tests(function_code, "divide")
    print("๐Ÿงช ์ƒ์„ฑ๋œ ํ…Œ์ŠคํŠธ:")
    print(tests)

๐ŸŽฏ ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉฐ

์™€! ์ •๋ง ๊ธด ์—ฌ์ •์ด์—ˆ์ฃ ? ๐Ÿ˜… ์šฐ๋ฆฌ๋Š” ์ง€๊ธˆ๊นŒ์ง€:

โœ… ์ฝ”๋“œ ํŒŒ์„œ๋กœ ๊ตฌ์กฐ ๋ถ„์„ํ•˜๊ธฐ
โœ… ์ •์  ๋ถ„์„์œผ๋กœ ๋ฌธ์ œ ์ฐพ๊ธฐ
โœ… AI๋กœ ์ง€๋Šฅํ˜• ๋ฆฌ๋ทฐ ์ƒ์„ฑํ•˜๊ธฐ
โœ… ์˜ˆ์œ ๋ฆฌํฌํŠธ ๋งŒ๋“ค๊ธฐ
โœ… CLI์™€ ์›น ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์ถ•ํ•˜๊ธฐ
โœ… Git ํ†ตํ•ฉ ๋ฐ ์ž๋™ํ™”ํ•˜๊ธฐ
โœ… ์‹ค์ „ ๋ฐฐํฌ๊นŒ์ง€!

์ด ๋ชจ๋“  ๊ฑธ ๋ฐฐ์› ์–ด์š”! ๐ŸŽ‰

๐Ÿ’ช ๋‹ค์Œ ๋‹จ๊ณ„: 1. ์ง์ ‘ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์‹คํ–‰ํ•ด๋ณด์„ธ์š”
2. ์ž์‹ ์˜ ํ”„๋กœ์ ํŠธ์— ์ ์šฉํ•ด๋ณด์„ธ์š”
3. ํŒ€์›๋“ค๊ณผ ๊ณต์œ ํ•˜๊ณ  ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์œผ์„ธ์š”
4. ์ง€์†์ ์œผ๋กœ ๊ฐœ์„ ํ•˜๊ณ  ํ™•์žฅํ•˜์„ธ์š”

๊ทธ๋ฆฌ๊ณ  ํ˜น์‹œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ๋ฐฐ์šฐ๊ณ  ์‹ถ๊ฑฐ๋‚˜ ๊ฐ€๋ฅด์น˜๊ณ  ์‹ถ๋‹ค๋ฉด, ์žฌ๋Šฅ๋„ท์—์„œ ๋‹ค์–‘ํ•œ ๊ฐœ๋ฐœ์ž๋“ค๊ณผ ๊ต๋ฅ˜ํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์ข‹์€ ๋ฐฉ๋ฒ•์ด์—์š”! ๐Ÿค

์ฝ”๋“œ ๋ฆฌ๋ทฐ๋Š” ๋‹จ์ˆœํžˆ ๋ฒ„๊ทธ๋ฅผ ์ฐพ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ๋” ๋‚˜์€ ๊ฐœ๋ฐœ์ž๋กœ ์„ฑ์žฅํ•˜๋Š” ๊ณผ์ •์ด์—์š”. AI ๋„์šฐ๋ฏธ๋Š” ๊ทธ ์—ฌ์ •์„ ํ•จ๊ป˜ํ•˜๋Š” ๋“ ๋“ ํ•œ ๋™๋ฃŒ๊ฐ€ ๋˜์–ด์ค„ ๊ฑฐ์˜ˆ์š”. ๐Ÿ˜Š

์—ฌ๋Ÿฌ๋ถ„์˜ ์ฝ”๋“œ ๋ฆฌ๋ทฐ AI ๋„์šฐ๋ฏธ๊ฐ€ ๋ฉ‹์ง€๊ฒŒ ์™„์„ฑ๋˜๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค! ๊ถ๊ธˆํ•œ ์ ์ด ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“  ์ปค๋ฎค๋‹ˆํ‹ฐ์— ๋ฌผ์–ด๋ณด์„ธ์š”. ์šฐ๋ฆฌ๋Š” ํ•จ๊ป˜ ์„ฑ์žฅํ•˜๋Š” ๊ฐœ๋ฐœ์ž ์ปค๋ฎค๋‹ˆํ‹ฐ๋‹ˆ๊นŒ์š”! ๐Ÿš€

Happy Coding! ์ฆ๊ฑฐ์šด ์ฝ”๋”ฉ ๋˜์„ธ์š”! ๐Ÿ’ปโœจ

๐ŸŽŠ ์ถ•ํ•˜ํ•ฉ๋‹ˆ๋‹ค!

๋‹น์‹ ์€ ์ด์ œ AI ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋„์šฐ๋ฏธ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

๊ณ„์†ํ•ด์„œ ๋ฐฐ์šฐ๊ณ , ์‹คํ—˜ํ•˜๊ณ , ๊ณต์œ ํ•˜์„ธ์š”! ๐ŸŒŸ

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.