From a1315f90e50f51cd747779e599a208466352e599 Mon Sep 17 00:00:00 2001 From: Variet Agent Date: Fri, 20 Mar 2026 06:46:48 +0900 Subject: [PATCH] =?UTF-8?q?feat(debate):=20Wiki.js=20=EC=97=B0=EB=8F=99=20?= =?UTF-8?q?=E2=80=94=20Working=20Document=20+=20Round=20Log=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=20=EC=97=85=EB=A1=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/debate_handler.py | 70 +++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/handlers/debate_handler.py b/handlers/debate_handler.py index 756fd22..1e39529 100644 --- a/handlers/debate_handler.py +++ b/handlers/debate_handler.py @@ -47,13 +47,14 @@ FILE_STABLE_DELAY = 5 # 파일 작성 완료 대기 (초) @dataclass class DebateSession: topic: str = "" + topic_slug: str = "" # Wiki 경로용 round: int = 0 max_rounds: int = MAX_ROUNDS active: bool = False - paused: bool = False # 사용자 응답 대기 중 + paused: bool = False current_speaker: str = "" history: list = field(default_factory=list) - pending_question: str = "" # 사용자에게 보낸 질문 + pending_question: str = "" class DebateHandler: @@ -72,8 +73,16 @@ class DebateHandler: await ctx.reply("⚠️ 이미 진행 중. `!debate-stop`으로 먼저 종료.") return + # slug 생성 + try: + from tools.wiki_client import WikiClient + slug = WikiClient.slugify(topic) + except Exception: + slug = topic[:15].replace(" ", "-").lower() + self.session = DebateSession( - topic=topic, active=True, max_rounds=MAX_ROUNDS, + topic=topic, topic_slug=slug, + active=True, max_rounds=MAX_ROUNDS, ) # 폴더 초기화 @@ -179,7 +188,10 @@ class DebateHandler: "speaker": speaker, "content": response, }) - # ⑤ Working Document 통합 편집 (Flash) + # ⑤ Round Log에 대화 전문 기록 (로컬 + Wiki.js) + await self._append_round_log(speaker, response) + + # ⑥ Working Document 통합 편집 (Flash + Wiki.js) await self._update_working_document(speaker, response) # ⑥ 양쪽 wiki/ 동기화 @@ -448,8 +460,7 @@ class DebateHandler: # ═══════════════════════════════════════════ async def _update_working_document(self, speaker: str, response: str): - """Flash가 AG 의견을 Working Document에 통합 편집.""" - # 현재 working document 읽기 + """Flash가 AG 의견을 Working Document에 통합 편집 + Wiki.js 업로드.""" wd_path = AGENT_PATHS["gemini"] / "wiki" / "working_document.md" current_doc = "" if wd_path.exists(): @@ -485,15 +496,58 @@ class DebateHandler: caller = GeminiCaller() updated = await caller.call_simple(merge_prompt, timeout=120) if updated and len(updated) > 50: - # gemini 폴더에 저장 (sync에서 양쪽 복사) wd_path.parent.mkdir(parents=True, exist_ok=True) wd_path.write_text(updated, encoding="utf-8") logger.info(f"Working Document 업데이트: {len(updated)}자") + # Wiki.js에 업로드 + await self._wiki_upsert( + f"debates/{self.session.topic_slug}/working-document", + f"{self.session.topic} — Working Document", + updated, + ) else: - logger.warning("Working Document 업데이트 실패 — Flash 응답 부족") + logger.warning("Working Document 업데이트 실패") except Exception as e: logger.error(f"Working Document 업데이트 오류: {e}") + async def _append_round_log(self, speaker: str, response: str): + """Round Log에 대화 전문 append + Wiki.js 업로드.""" + log_path = AGENT_PATHS["gemini"] / "wiki" / "round_log.md" + # 기존 내용 읽기 + existing = "" + if log_path.exists(): + existing = log_path.read_text(encoding="utf-8") + + emoji = AGENT_EMOJI.get(speaker, "👤") + entry = ( + f"\n---\n\n" + f"## Round {self.session.round} — {emoji} {speaker}\n\n" + f"{response}\n" + ) + updated_log = existing + entry + log_path.parent.mkdir(parents=True, exist_ok=True) + log_path.write_text(updated_log, encoding="utf-8") + + # Wiki.js에 업로드 + await self._wiki_upsert( + f"debates/{self.session.topic_slug}/round-log", + f"{self.session.topic} — Round Log", + updated_log, + ) + + async def _wiki_upsert(self, path: str, title: str, content: str): + """Wiki.js에 페이지 upsert.""" + try: + from tools.wiki_client import WikiClient + client = WikiClient() + await client.upsert_page( + path=path, title=title, content=content, + tags=["debate", self.session.topic_slug], + ) + logger.info(f"Wiki.js 업로드: {path}") + except Exception as e: + logger.warning(f"Wiki.js 업로드 실패 ({path}): {e}") + def _sync_wiki(self): """gemini wiki/ 폴더 내용을 opus wiki/에 동기화.""" src = AGENT_PATHS["gemini"] / "wiki"