# 요청에서 코드 파일 경로 추출
code_path = request.code_path
# 코드 파일 읽기 시도
try:
with open(code_path, "r", encoding="utf-8") as f:
code = f.read()
except Exception as e:
# 파일 읽기 실패 시 오류 메시지 반환
return agents_pb2.CodeResponse(summary=f"[Static] 파일 읽기 오류: {e}")
# AST 파싱 및 분석 시도
try:
# 코드를 AST로 파싱
tree = ast.parse(code)
# StaticVisitor 인스턴스 생성 및 AST 트리 순회
visitor = StaticVisitor()
visitor.visit(tree)
if not visitor.issues:
# 발견된 이슈가 없는 경우
summary = "[Static] 정적 분석 결과, 주요 취약점 패턴 없음."
else:
# 발견된 이슈들을 줄바꿈으로 구분하여 요약 생성
summary = "[Static] 정적 분석 이슈:\n- " + "\n- ".join(visitor.issues)
except Exception as e:
# AST 파싱 실패 시 오류 메시지 반환
summary = f"[Static] AST 파싱 오류: {e}"
# CodeResponse 객체를 생성하여 반환
return agents_pb2.CodeResponse(summary=summary)