From 55efebd395140075826186bb4195947f4f5ec541 Mon Sep 17 00:00:00 2001 From: Pnant <73925474+Panniantong@users.noreply.github.com> Date: Tue, 10 Mar 2026 10:08:36 +0800 Subject: [PATCH] fix(twitter): warn when xreach < 0.3.2 (longform tweet support) (#127) xreach-cli v0.3.2 added: - extractTweetText() preferring note_tweet.text for long tweets - X Article URL support (/article/ path) Previously, doctor reported 'ok' even when the user had v0.3.0/v0.3.1 installed, silently failing to read longform tweets. Now check() reads `xreach --version` and returns a warn with upgrade instructions if the version is below 0.3.2. Closes #126 Co-authored-by: neo_minion1 --- agent_reach/channels/twitter.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/agent_reach/channels/twitter.py b/agent_reach/channels/twitter.py index b81c1f1..56f4d54 100644 --- a/agent_reach/channels/twitter.py +++ b/agent_reach/channels/twitter.py @@ -5,6 +5,19 @@ import shutil import subprocess from .base import Channel +# Minimum xreach-cli version with longform tweet and X Article support. +# v0.3.2 added: extractTweetText() preferring note_tweet for long tweets (#aad6a16) +# and X Article URL support (/article/ path, #2e05825). +_MIN_XREACH_VERSION = (0, 3, 2) + + +def _parse_version(ver_str: str) -> tuple[int, ...]: + """Parse a semver string like '0.3.2' into a tuple (0, 3, 2).""" + try: + return tuple(int(x) for x in ver_str.strip().split(".")[:3]) + except (ValueError, AttributeError): + return (0, 0, 0) + class TwitterChannel(Channel): name = "twitter" @@ -24,13 +37,31 @@ class TwitterChannel(Channel): "xreach CLI 未安装。搜索可通过 Exa 替代。安装:\n" " npm install -g xreach-cli" ) + # Check version — longform tweet support requires >= 0.3.2 + try: + ver_result = subprocess.run( + [xreach, "--version"], capture_output=True, + encoding="utf-8", errors="replace", timeout=5 + ) + version_str = (ver_result.stdout or ver_result.stderr).strip() + version_tuple = _parse_version(version_str) + if version_tuple < _MIN_XREACH_VERSION: + min_str = ".".join(str(x) for x in _MIN_XREACH_VERSION) + return "warn", ( + f"xreach CLI 版本过旧(当前 {version_str},需 >= {min_str})。" + f"旧版本无法读取长文推文(note_tweet)和 X Article。升级:\n" + f" npm install -g xreach-cli@latest" + ) + except Exception: + pass # version check failure is non-fatal; proceed to auth check + try: r = subprocess.run( [xreach, "auth", "check"], capture_output=True, encoding="utf-8", errors="replace", timeout=10 ) if r.returncode == 0: - return "ok", "完整可用(读取、搜索推文)" + return "ok", "完整可用(读取、搜索推文,含长文/X Article)" return "warn", ( "xreach CLI 已安装但未配置 Cookie。运行:\n" " agent-reach configure twitter-cookies \"auth_token=xxx; ct0=yyy\""