fix(bridge): isolate DOM observation scope and strip UI noise (TypeScript declarations, metrics) from Discord pending approval embeds

This commit is contained in:
Variet Worker
2026-04-11 17:25:33 +09:00
parent 7630bf1f8c
commit 70dc301dca
2 changed files with 182 additions and 99 deletions

48
bot.py
View File

@@ -724,15 +724,55 @@ class GravityBot(commands.Bot):
desc_parts = []
if header:
desc_parts.append(header)
desc_parts.append(f"**명령:** `{request.command[:200]}`")
# Clean command text (remove "Running2" artifacts → "Running 2")
cmd_text = request.command[:200]
import re
cmd_text = re.sub(r'Running(\d)', r'Running \1', cmd_text)
desc_parts.append(f"**명령:** `{cmd_text}`")
if buttons:
btn_names = [b.get("text", "?") for b in buttons]
desc_parts.append(f"**선택지:** {' / '.join(btn_names)}")
if request.description:
desc_parts.append(request.description[:500])
# Clean description: strip noise headers and garbage
desc_raw = request.description or ""
# Remove old-style headers
desc_raw = re.sub(r'\[AI 본문 요약\]\s*', '', desc_raw)
desc_raw = re.sub(r'\[결행 명령\]\s*', '', desc_raw)
# Remove lines that are clearly noise
desc_lines = desc_raw.split('\n')
clean_desc_lines = []
for dline in desc_lines:
dline_stripped = dline.strip()
if not dline_stripped:
continue
# Skip UI artifacts
if dline_stripped in ('chevron_right', 'chevron_left', 'close', 'check',
'content_copy', 'expand_more', 'expand_less',
'Show more', 'Show less', 'Copy', 'Edit', 'Copied!'):
continue
# Skip "Thought for Xs"
if re.match(r'^Thought for \d+', dline_stripped):
continue
# Skip TypeScript declarations and file paths
if re.match(r'^(declare|import|export)\s+(class|function|interface|type|enum|const)', dline_stripped):
continue
if re.search(r'\.ts:\d+:', dline_stripped):
continue
if re.search(r'extension.*src.*sdk', dline_stripped, re.IGNORECASE):
continue
clean_desc_lines.append(dline_stripped)
clean_desc = '\n'.join(clean_desc_lines).strip()
if clean_desc and len(clean_desc) > 3:
# Truncate and wrap in code block for readability
if len(clean_desc) > 300:
clean_desc = clean_desc[:300] + ''
desc_parts.append(f"```\n{clean_desc}\n```")
embed = discord.Embed(
title="⚠️ 승인 요청",
title=f"⚠️ 승인 요청{request.step_type or 'action'}",
description="\n".join(desc_parts),
color=discord.Color.orange(),
timestamp=datetime.now(timezone.utc),