refactor(api): Phase A P1 快速勝利 (3 項)
1. 常數提取: SSE_DELAY_SECONDS, MAX_APPROVAL_DISPLAY 2. 錯誤訊息安全化: sanitize_error_message() 移除敏感資訊 3. CI/CD alertname 配置化: is_cicd_alertname() 函數 首席架構師審查 P1 改進 (非阻塞) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,12 @@ import uuid
|
||||
from enum import Enum
|
||||
from typing import Protocol, runtime_checkable
|
||||
|
||||
from src.core.constants import (
|
||||
ERROR_MESSAGE_DISPLAY_LENGTH,
|
||||
MAX_APPROVAL_DISPLAY,
|
||||
SSE_DELAY_SECONDS,
|
||||
sanitize_error_message,
|
||||
)
|
||||
from src.core.logging import get_logger
|
||||
from src.core.sse import EventType, SSEEvent, get_publisher
|
||||
from src.models.terminal import (
|
||||
@@ -511,7 +517,7 @@ class TerminalService:
|
||||
publisher, topic, "Approval-Query", "completed",
|
||||
result={"pending_count": len(pending_approvals)}
|
||||
)
|
||||
await asyncio.sleep(0.3)
|
||||
await asyncio.sleep(SSE_DELAY_SECONDS)
|
||||
|
||||
if not pending_approvals:
|
||||
await self._publish_thought(
|
||||
@@ -522,14 +528,15 @@ class TerminalService:
|
||||
|
||||
# 顯示待簽核清單摘要
|
||||
summary_lines = [f"發現 {len(pending_approvals)} 個待簽核項目:"]
|
||||
for i, approval in enumerate(pending_approvals[:5], 1): # 最多顯示 5 個
|
||||
for i, approval in enumerate(pending_approvals[:MAX_APPROVAL_DISPLAY], 1):
|
||||
risk = approval.risk_level.value.upper() if approval.risk_level else "UNKNOWN"
|
||||
summary_lines.append(
|
||||
f" {i}. [{risk}] {approval.action[:50]}"
|
||||
)
|
||||
|
||||
if len(pending_approvals) > 5:
|
||||
summary_lines.append(f" ... 還有 {len(pending_approvals) - 5} 個")
|
||||
if len(pending_approvals) > MAX_APPROVAL_DISPLAY:
|
||||
remaining = len(pending_approvals) - MAX_APPROVAL_DISPLAY
|
||||
summary_lines.append(f" ... 還有 {remaining} 個")
|
||||
|
||||
await self._publish_thought(
|
||||
publisher, topic, "Executor",
|
||||
@@ -561,11 +568,11 @@ class TerminalService:
|
||||
logger.error("approval_query_failed", error=str(e))
|
||||
await self._publish_tool_call(
|
||||
publisher, topic, "Approval-Query", "failed",
|
||||
result={"error": str(e)[:100]}
|
||||
result={"error": sanitize_error_message(str(e))}
|
||||
)
|
||||
await self._publish_thought(
|
||||
publisher, topic, "System",
|
||||
f"查詢簽核項目失敗: {str(e)[:50]}"
|
||||
f"查詢簽核項目失敗: {sanitize_error_message(str(e), ERROR_MESSAGE_DISPLAY_LENGTH)}"
|
||||
)
|
||||
|
||||
async def _handle_metrics_query(
|
||||
|
||||
Reference in New Issue
Block a user