fix(windows): force UTF-8 in channel subprocesses and MCP server env (#345)
Extracted from #318 (the UTF-8/doctor core, minus the env-wrapper feature): - new agent_reach/utils/process.py: utf8_subprocess_env() + mcporter_utf8_env_args() — Windows GBK consoles otherwise corrupt Chinese output from mcporter/MCP child processes - weibo/douyin/linkedin checks and weibo install/registration now pass the UTF-8 env (and register the MCP server with --env PYTHONUTF8=1) - youtube: extract _has_js_runtime_config() with an OSError guard so an unreadable yt-dlp config can't crash doctor - test_skill_command: open SKILL.md with explicit utf-8 (Windows GBK default broke these tests) Co-authored-by: chidao <2980933590@qq.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from agent_reach.utils.process import utf8_subprocess_env
|
||||
|
||||
from .base import Channel
|
||||
|
||||
|
||||
@@ -31,7 +34,8 @@ class DouyinChannel(Channel):
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[mcporter, "config", "list"], capture_output=True,
|
||||
encoding="utf-8", errors="replace", timeout=5
|
||||
encoding="utf-8", errors="replace", timeout=5,
|
||||
env=utf8_subprocess_env(),
|
||||
)
|
||||
if "douyin" not in r.stdout:
|
||||
return "off", (
|
||||
@@ -47,7 +51,8 @@ class DouyinChannel(Channel):
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[mcporter, "list", "douyin"],
|
||||
capture_output=True, encoding="utf-8", errors="replace", timeout=15
|
||||
capture_output=True, encoding="utf-8", errors="replace", timeout=15,
|
||||
env=utf8_subprocess_env(),
|
||||
)
|
||||
if r.returncode == 0 and r.stdout.strip():
|
||||
return "ok", "完整可用(视频解析、下载链接获取)"
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from agent_reach.utils.process import utf8_subprocess_env
|
||||
|
||||
from .base import Channel
|
||||
|
||||
|
||||
@@ -28,7 +31,8 @@ class LinkedInChannel(Channel):
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[mcporter, "config", "list"], capture_output=True,
|
||||
encoding="utf-8", errors="replace", timeout=5
|
||||
encoding="utf-8", errors="replace", timeout=5,
|
||||
env=utf8_subprocess_env(),
|
||||
)
|
||||
if "linkedin" in r.stdout.lower():
|
||||
return "ok", "完整可用(Profile、公司、职位搜索)"
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from agent_reach.utils.process import utf8_subprocess_env
|
||||
|
||||
from .base import Channel
|
||||
|
||||
|
||||
@@ -24,26 +27,30 @@ class WeiboChannel(Channel):
|
||||
"需要 mcporter + mcp-server-weibo。安装步骤:\n"
|
||||
" 1. npm install -g mcporter\n"
|
||||
" 2. pip install git+https://github.com/Panniantong/mcp-server-weibo.git\n"
|
||||
" 3. mcporter config add weibo --command 'mcp-server-weibo'\n"
|
||||
" 3. mcporter config add weibo --command 'mcp-server-weibo' "
|
||||
"--env PYTHONUTF8=1 --env PYTHONIOENCODING=utf-8\n"
|
||||
" 详见 https://github.com/Panniantong/mcp-server-weibo"
|
||||
)
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[mcporter, "config", "list"], capture_output=True,
|
||||
encoding="utf-8", errors="replace", timeout=5
|
||||
encoding="utf-8", errors="replace", timeout=5,
|
||||
env=utf8_subprocess_env(),
|
||||
)
|
||||
if "weibo" not in r.stdout:
|
||||
return "off", (
|
||||
"mcporter 已装但微博 MCP 未配置。运行:\n"
|
||||
" pip install git+https://github.com/Panniantong/mcp-server-weibo.git\n"
|
||||
" mcporter config add weibo --command 'mcp-server-weibo'"
|
||||
" mcporter config add weibo --command 'mcp-server-weibo' "
|
||||
"--env PYTHONUTF8=1 --env PYTHONIOENCODING=utf-8"
|
||||
)
|
||||
except Exception:
|
||||
return "off", "mcporter 连接异常"
|
||||
try:
|
||||
r = subprocess.run(
|
||||
[mcporter, "list", "weibo"], capture_output=True,
|
||||
encoding="utf-8", errors="replace", timeout=15
|
||||
encoding="utf-8", errors="replace", timeout=15,
|
||||
env=utf8_subprocess_env(),
|
||||
)
|
||||
if r.returncode == 0 and "search_users" in r.stdout:
|
||||
return "ok", "完整可用(热搜、搜索、用户动态、评论)"
|
||||
|
||||
@@ -9,6 +9,16 @@ from agent_reach.utils.text import read_utf8_text
|
||||
from .base import Channel
|
||||
|
||||
|
||||
def _has_js_runtime_config(config_path) -> bool:
|
||||
"""Return whether yt-dlp config explicitly enables a JS runtime."""
|
||||
try:
|
||||
if not config_path.exists():
|
||||
return False
|
||||
return "--js-runtimes" in read_utf8_text(config_path)
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
class YouTubeChannel(Channel):
|
||||
name = "youtube"
|
||||
description = "YouTube 视频和字幕"
|
||||
@@ -36,10 +46,7 @@ class YouTubeChannel(Channel):
|
||||
has_deno = shutil.which("deno")
|
||||
if not has_deno:
|
||||
ytdlp_config = get_ytdlp_config_path()
|
||||
has_js_config = False
|
||||
if ytdlp_config.exists():
|
||||
has_js_config = "--js-runtimes" in read_utf8_text(ytdlp_config)
|
||||
if not has_js_config:
|
||||
if not _has_js_runtime_config(ytdlp_config):
|
||||
return "warn", (
|
||||
f"yt-dlp 已安装但未配置 JS runtime。运行:\n {render_ytdlp_fix_command()}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user