[V10.4-A] 加強 commit-quality Hook + P9 文件歸檔
新增 Edit/Write/MultiEdit 事件攔截(原僅攔截 git commit Bash 指令), 補齊 getenv fallback 模式偵測,防止 hardcoded Token 透過工具直寫入檔案。 - .claude/hooks/commit-quality.js: 改寫為 PreToolUse JSON 格式,覆蓋 Edit/Write/MultiEdit - .claude/settings.json: 新增 Edit|Write|MultiEdit|Bash matcher 註冊 - .claude/hooks/__test__/commit-quality.test.sh: 4 case 自動化測試 - docs/guides/DISK_EXPANSION_GUIDE.md: 磁碟擴充 SOP 歸檔 - docs/p9_completion_report_*.md: P9-1 + P9-2 Sprint 完成報告 - docs/refactor/callback_prefix_proposal.md: 308 按鈕回呼前綴分析(Method C) - docs/refactor/openclaw_bot_routes_split_plan.md: 5999 行神檔拆分計畫 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
74
services/mcp_context_service.py
Normal file
74
services/mcp_context_service.py
Normal file
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
services/mcp_context_service.py
|
||||
MCP (Model Context Protocol) 橋接服務
|
||||
此檔案旨在橋接 OpenClaw 戰略分析所需的外部情報與 MCP 集成層。
|
||||
"""
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from services.mcp_collector_service import mcp_collector
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class MCPRouter:
|
||||
"""MCP 路由分發器(模擬或橋接至現有收集器)"""
|
||||
@staticmethod
|
||||
def get_context(topic: str) -> str:
|
||||
return mcp_collector.collect_topic(topic)
|
||||
|
||||
def build_mcp_context(query: str = "", topics: list = None) -> str:
|
||||
"""構建完整 MCP 上下文供 AI 分析使用"""
|
||||
if topics is None:
|
||||
topics = ["market_trends", "holiday_calendar", "seasonal_insights"]
|
||||
|
||||
results = []
|
||||
for topic in topics:
|
||||
content = mcp_collector.collect_topic(topic)
|
||||
if content:
|
||||
results.append(f"【{topic}】\n{content}")
|
||||
|
||||
# 加入靜態輔助資訊
|
||||
results.append(mcp_collector.get_holiday_context())
|
||||
results.append(mcp_collector.get_seasonal_context())
|
||||
|
||||
return "\n\n".join(results)
|
||||
|
||||
def query_mcp(question: str) -> str:
|
||||
"""通用的 MCP 查詢入口"""
|
||||
# 這裡可以根據 question 決定回傳哪些主題內容
|
||||
return build_mcp_context(question)
|
||||
|
||||
def get_tw_media_news() -> str:
|
||||
"""取得台灣媒體新聞情報"""
|
||||
return mcp_collector.collect_topic("market_trends")
|
||||
|
||||
def get_ecommerce_news() -> str:
|
||||
"""取得台灣電商新聞行情"""
|
||||
return mcp_collector.collect_topic("competitor_intel")
|
||||
|
||||
def get_taiwan_trends() -> str:
|
||||
"""取得台灣 Google 趨勢或熱搜"""
|
||||
return mcp_collector.collect_topic("market_trends")
|
||||
|
||||
def get_dcard_trends() -> str:
|
||||
"""取得 Dcard 熱門討論洞察"""
|
||||
return mcp_collector.collect_topic("consumer_sentiment")
|
||||
|
||||
def get_youtube_trending() -> str:
|
||||
"""取得 YouTube 台灣熱門趨勢"""
|
||||
return mcp_collector.collect_topic("market_trends")
|
||||
|
||||
def get_taiwan_weather() -> str:
|
||||
"""取得台灣天氣概況(影響消費行為)"""
|
||||
# 簡易橋接,可用搜尋 Grounding 獲取
|
||||
return mcp_collector.collect_topic("台灣近日天氣與氣溫概況")
|
||||
|
||||
def get_twbank_exchange_rates() -> str:
|
||||
"""取得台幣匯率概況(影響跨境採購)"""
|
||||
return mcp_collector.collect_topic("台幣匯率趨勢")
|
||||
|
||||
def get_upcoming_events() -> str:
|
||||
"""取得近期重要行事曆事件"""
|
||||
return mcp_collector.get_holiday_context()
|
||||
Reference in New Issue
Block a user