feat: Task Pipeline + Planner E2E 성공 — stdin기반 GeminiCaller 확정 #task-189 #task-190

This commit is contained in:
quantlab
2026-03-06 17:37:06 +09:00
parent 9192770300
commit 57c9cb6143
7 changed files with 357 additions and 26 deletions

View File

@@ -1,10 +1,10 @@
"""GeminiCaller — gemini -p 역할별 headless 호출.
"""GeminiCaller — gemini headless 호출.
stdin으로 시스템 프롬프트 + 컨텍스트를 직접 전달합니다.
cmd /c 래핑으로 PowerShell 실행 정책 우회.
"""
import asyncio
import json
import time
from pathlib import Path
@@ -21,12 +21,9 @@ class GeminiCaller:
self.last_call_time = 0.0
async def call(self, role: str, context: str, timeout: int = 120) -> str:
"""역할별 프롬프트로 gemini -p 호출.
"""역할별 프롬프트로 gemini 호출.
Args:
role: 프롬프트 파일명 (planner, coder, reviewer, tester)
context: 전달할 컨텍스트
timeout: 최대 대기 시간 (초)
시스템 프롬프트와 컨텍스트를 하나로 합쳐 stdin으로 전달.
"""
# 시스템 프롬프트 로드
prompt_file = ROLE_PROMPTS_DIR / f"{role}.md"
@@ -35,31 +32,24 @@ class GeminiCaller:
else:
system_prompt = f"You are a {role}. Respond in Korean."
# cmd 구성
cmd_parts = ["gemini", "-p", context]
if system_prompt:
cmd_parts.extend(["--system", system_prompt])
cmd_parts.extend(["--approval-mode", "yolo"])
if self.project_path:
cmd_parts.extend(["--include-directories", self.project_path])
# cmd /c 래핑 (PowerShell 실행 정책 우회)
escaped_context = context.replace('"', '\\"')
cmd_str = f'gemini -p "{escaped_context}" --approval-mode yolo'
if self.project_path:
cmd_str += f' --include-directories "{self.project_path}"'
# 시스템 프롬프트 + 컨텍스트를 하나의 입력으로 합침
full_input = (
f"=== SYSTEM INSTRUCTIONS ===\n"
f"{system_prompt}\n\n"
f"=== USER INPUT ===\n"
f"{context}"
)
try:
proc = await asyncio.create_subprocess_shell(
f'cmd /c {cmd_str}',
proc = await asyncio.create_subprocess_exec(
"cmd", "/c", "gemini --approval-mode yolo",
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
stdout, stderr = await asyncio.wait_for(
proc.communicate(), timeout=timeout
proc.communicate(input=full_input.encode("utf-8")),
timeout=timeout
)
self.call_count += 1
@@ -85,3 +75,5 @@ class GeminiCaller:
async def call_simple(self, prompt: str, timeout: int = 60) -> str:
"""시스템 프롬프트 없이 단순 호출."""
return await self.call("default", prompt, timeout)