fix(anime): 파이프라인 5건 수정 — 에피소드 정규식(v2/S01E), 릴리스 그룹 필터, 자막 보호, 배치 다운로드, 타임아웃

This commit is contained in:
2026-03-15 08:27:08 +09:00
parent 63818999d9
commit 9f74812710
40 changed files with 2759 additions and 815 deletions

View File

@@ -1,8 +1,7 @@
"""Task Pipeline -- Plan -> Code(에이전트) -> Review -> 재시도 -> 총평 -> 기록.
"""Task Pipeline -- Agent 1회 호출 + 선택적 Review.
Coder는 에이전트 모드로 프로젝트 디렉토리에서 실행되어
Gemini가 직접 파일을 읽고/쓰고/명령을 실행합니다.
리뷰 실패 시 최대 MAX_REVIEW_RETRIES회 재시도합니다.
Gemini CLI agent 모드가 plan+code+verify를 한 세션에서 수행합니다.
기존 5단계(Plan→Code→PlannerVerify→Review→Summarize) → 2단계로 단순화.
"""
import asyncio
@@ -15,12 +14,11 @@ from core.context_manager import ContextManager
from core.gemini_caller import GeminiCaller, GeminiCallError
from core.docs_manager import DocsManager
MAX_REVIEW_RETRIES = 2
logger = logging.getLogger("variet.pipeline")
class TaskPipeline:
"""작업 파이프라인: Plan -> Code(에이전트) -> Review(재시도) -> 기록."""
"""작업 파이프라인: Agent 1회 호출 → 선택적 Review."""
def __init__(self, project_path: str, token_budget: int = 50_000,
docs_subpath: str = "docs/wiki"):
@@ -37,7 +35,7 @@ class TaskPipeline:
return self
# ──────────────────────────────────────────
# Docs 컨텍스트 (모든 호출에 주입)
# Docs 컨텍스트
# ──────────────────────────────────────────
def _docs_context(self) -> str:
@@ -50,137 +48,79 @@ class TaskPipeline:
)
# ──────────────────────────────────────────
# Plan
# Agent 통합 실행 (핵심)
# ──────────────────────────────────────────
async def plan(self, user_request: str) -> dict:
"""Planner로 태스크 분해 (에이전트 모드 — 직접 처리 가능)."""
context = self.ctx.gather(user_request)
docs_ctx = self._docs_context()
async def execute(self, user_request: str, history: str = "",
progress_callback=None, role: str = "agent",
timeout: int = None) -> dict:
"""Agent 1회 호출 — plan+code+verify+report 통합.
prompt = (
f"## User Request\n{user_request}\n\n"
f"## Project Context\n{context}\n\n"
f"## Project Docs\n{docs_ctx}\n\n"
f"Analyze this request. If simple, handle it directly (direct: true). "
f"If complex, decompose into tasks (direct: false)."
)
Args:
role: 'agent'(코딩) 또는 'operator'(도구 실행)
progress_callback: async callable(status_text) — 진행 상태 콜백
timeout: 타임아웃(초). None이면 operator=180, agent=600
response = await self.gemini.call_agent(
"planner", prompt, cwd=self.project_path, timeout=180,
)
self._log("plan", user_request, response)
plan = self._extract_json(response)
return plan or {"summary": response, "tasks": [], "raw": response}
# ──────────────────────────────────────────
# Code (에이전트 모드 — Gemini가 직접 파일 쓰기)
# ──────────────────────────────────────────
async def code(self, task: dict) -> str:
"""에이전트 모드로 코딩 — Gemini가 직접 파일 생성/수정."""
docs_ctx = self._docs_context()
prompt = (
f"## Task\n{json.dumps(task, ensure_ascii=False, indent=2)}\n\n"
f"## Project Docs\n{docs_ctx}\n\n"
f"위 태스크를 구현하세요. 파일을 직접 생성/수정하세요."
)
response = await self.gemini.call_agent(
"coder", prompt, cwd=self.project_path, timeout=300,
)
self._log("code", task.get("title", ""), response)
return response
# ──────────────────────────────────────────
# Code 병렬 실행
# ──────────────────────────────────────────
async def code_parallel(self, tasks: list[dict]) -> list[str]:
"""여러 태스크를 병렬로 코딩 (에이전트 모드)."""
results = await asyncio.gather(
*[self.code(task) for task in tasks],
return_exceptions=True,
)
processed = []
for i, result in enumerate(results):
if isinstance(result, Exception):
error_msg = f"[ERROR] Task {i+1} 실패: {result}"
self._log("code_error", tasks[i].get("title", ""), error_msg)
processed.append(error_msg)
else:
processed.append(result)
return processed
# ──────────────────────────────────────────
# Planner 자가 검증 (오케스트레이션)
# ──────────────────────────────────────────
async def planner_verify(
self, user_request: str, plan: dict,
code_outputs: list[str],
) -> dict:
"""Planner가 자기 계획의 달성 여부를 에이전트 모드로 검증.
프로젝트 디렉토리에서 직접 파일을 읽어서 계획 충족 여부를 판단합니다.
Returns:
dict: {title, summary, changes, verified, warnings, next_steps}
"""
agent_reports = "\n".join(
f"--- Agent {i+1} ---\n{output}"
for i, output in enumerate(code_outputs)
)
if timeout is None:
timeout = 600
prompt = (
f"## 원래 사용자 요청\n{user_request}\n\n"
f"## 내가 세운 계획\n{json.dumps(plan, ensure_ascii=False, indent=2)}\n\n"
f"## 에이전트 보고\n{agent_reports}\n\n"
f"## 판단 요청\n"
f"현재 디렉토리의 프로젝트 파일을 직접 읽어서 계획이 충족되었는지 확인하세요.\n"
f"필요한 파일만 선택적으로 읽으세요.\n\n"
f"충족되었으면 satisfied=true.\n"
f"미충족이면 satisfied=false + 부족한 부분을 해결할 추가 태스크를 생성하세요.\n\n"
f"반드시 아래 JSON만 출력하세요:\n"
f"```json\n"
f'{{\n'
f' "satisfied": true|false,\n'
f' "feedback": "판단 근거 (한국어)",\n'
f' "additional_tasks": [\n'
f' {{"id": 1, "title": "추가 태스크", "description": "구현 내용", "type": "modify"}}\n'
f' ]\n'
f'}}\n'
f"```"
)
# operator 모드는 프로젝트 컨텍스트/문서 불필요 (도구만 실행)
if role == "operator":
history_section = ""
if history:
history_section = f"## 대화 히스토리\n{history}\n\n"
prompt = (
f"{history_section}"
f"## 사용자 요청\n{user_request}\n\n"
f"위 요청에 맞는 도구를 바로 실행하고 결과를 JSON으로 보고하세요."
)
else:
context = self.ctx.gather(user_request)
docs_ctx = self._docs_context()
history_section = ""
if history:
history_section = f"## 대화 히스토리\n{history}\n\n"
prompt = (
f"{history_section}"
f"## 사용자 요청\n{user_request}\n\n"
f"## 프로젝트 컨텍스트\n{context}\n\n"
f"## 프로젝트 문서\n{docs_ctx}\n\n"
f"위 요청을 분석하고, 계획을 세우고, 필요한 도구를 실행하고, "
f"결과를 JSON 보고서로 출력하세요."
)
response = await self.gemini.call_agent(
"planner", prompt, cwd=self.project_path, timeout=180,
role, prompt, cwd=self.project_path, timeout=timeout,
progress_callback=progress_callback,
)
self._log("planner_verify", user_request, response)
self._log("execute", user_request, response)
result = self._extract_json(response)
return result or {"satisfied": True, "feedback": response}
return result or {
"title": "작업 완료",
"summary": response[:500],
"changes": [],
"verified": False,
"warnings": ["JSON 보고서 파싱 실패 — 원본 응답 참조"],
"next_steps": [],
"raw": response,
}
# ──────────────────────────────────────────
# Batch Review
# 선택적 독립 리뷰
# ──────────────────────────────────────────
async def batch_review(self, tasks: list[dict], code_outputs: list[str]) -> dict:
"""에이전트 모드로 프로젝트 파일을 직접 읽어 리뷰."""
task_summaries = []
for i, task in enumerate(tasks):
title = task.get("title", task.get("description", f"Task {i+1}"))
task_summaries.append(f"### Task {i+1}: {title}")
agent_reports = []
for i, output in enumerate(code_outputs):
agent_reports.append(f"--- Agent {i+1} 보고 ---\n{output}")
async def review(self, user_request: str, agent_report: str) -> dict:
"""독립 리뷰어 — agent 작업 결과를 검증.
agent가 자체 검증을 하지만, 중요한 작업에는 독립 리뷰를 추가할 수 있음.
"""
prompt = (
f"## 요청된 태스크\n{chr(10).join(task_summaries)}\n\n"
f"## 에이전트 보고\n{chr(10).join(agent_reports)}\n\n"
f"## 원래 사용자 요청\n{user_request}\n\n"
f"## Agent 보고\n{agent_report}\n\n"
f"현재 디렉토리의 프로젝트 파일을 직접 읽어서 리뷰하세요.\n"
f"필요한 파일만 선택적으로 확인하세요."
)
@@ -188,41 +128,33 @@ class TaskPipeline:
response = await self.gemini.call_agent(
"reviewer", prompt, cwd=self.project_path, timeout=300,
)
self._log("batch_review", f"{len(tasks)} tasks", response)
self._log("review", user_request, response)
review = self._extract_json(response)
return review or {"passed": True, "summary": response, "raw": response}
result = self._extract_json(response)
return result or {"passed": True, "summary": response, "raw": response}
# ──────────────────────────────────────────
# 총평
# NLU 분류 (chat/task/anime 구분에 사용)
# ──────────────────────────────────────────
async def summarize(self, user_request: str, plan: dict,
code_outputs: list[str], review: dict) -> dict:
"""전체 작업 결과 종합 총평."""
prompt = (
f"## 원래 요청\n{user_request}\n\n"
f"## 태스크 수\n{len(plan.get('tasks', []))}\n\n"
f"## 리뷰 결과\n{review.get('summary', str(review))}\n\n"
f"## 코딩 결과 요약\n"
f"{chr(10).join(code_outputs)}\n\n"
f"위 정보를 바탕으로 총평을 작성하세요."
async def classify(self, user_input: str, history: str = "") -> dict:
"""통합 프롬프트로 의도 분류 (Orchestrator에서 위임).
이전 _unified_call의 역할을 담당합니다.
"""
docs_ctx = self._docs_context()
context = (
f"{history}"
f"## Workspace\nPath: {self.project_path}\n\n"
f"## Project Docs\n{docs_ctx}\n\n"
f"## User Message\n{user_input}"
)
response = await self.gemini.call_agent(
"summarizer", prompt, cwd=self.project_path, timeout=120,
)
self._log("summarize", user_request, response)
summary = self._extract_json(response)
return summary or {
"title": "작업 완료",
"summary": response,
"changes": [],
"warnings": [],
"next_steps": [],
}
raw = await self.gemini.call("unified", context, timeout=120)
result = self._extract_json(raw)
return result or {"mode": "chat", "response": raw}
# ──────────────────────────────────────────
# 유틸리티