Skip to content

Give your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.

fix: pass upstream error messages and help through unchanged

Pnant9b7df6b2f1c5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 30c148c6..c17f8ae7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,7 @@ English:
- 浏览器渠道可以并行查询:同一平台最多 2 条、合计 4 条同时跑,多出来的排队而不是立刻报"正忙";登录窗口、退出登录等操作等正在跑的查询结束再做。
- 没登录时报"需要登录"而不是"上游工具坏了":雪球社区(错误码 400016)、B站字幕(没有 B站登录)、LinkedIn(专用浏览器里没有 LinkedIn 登录)。
- 从 1.5 升级更顺:update.md 先看版本再分流;`agent-reach update` 遇到 pip/pipx 装的旧版会自己换成 uv 安装;`setup` 删掉旧版 Agent Reach 程序(只删它自己,不动其他工具),安装汇报说明保留了什么、变了什么、以前用过哪些渠道可以加回来。安装地址改为始终指向最新正式版。
+- 上游工具出错时,报错原话和它自带的处理建议原样交给 AI,并用 `error.source` 标明是哪个工具说的;不再用 Reach 自己编的建议覆盖("要登录"仍给 Reach 自己专用浏览器的登录步骤)。
English (technical):
- Browser channels share one profile, close after ten idle minutes and reopen on demand.
@@ -52,6 +53,7 @@ English (technical):
- Browser channels run queries in parallel: up to 2 per platform and 4 in total, with the rest queued instead of failing BUSY at once; login windows, logout and browser setup wait for running queries.
- Report NEED_LOGIN instead of UPSTREAM_BROKEN when not logged in: Xueqiu community (error 400016), Bilibili subtitles (no Bilibili login), LinkedIn (no LinkedIn login in the dedicated browser).
- Smoother upgrade from 1.5: update.md checks the version first; `agent-reach update` moves a pip/pipx install to uv by itself; `setup` removes the old Agent Reach program (only Agent Reach itself) and the install report explains what was kept, what changed and which old channels can be added back. Install URLs always point at the latest release.
+- Upstream errors reach the agent unchanged: the tool's own message and help, with `error.source` naming the tool. Reach no longer replaces them with its own advice (NEED_LOGIN still gives Reach's dedicated-browser login steps).
### ✨ New / 新增
diff --git a/agent_reach/backends/opencli.py b/agent_reach/backends/opencli.py
index c0a11d6b..da3cc257 100644
--- a/agent_reach/backends/opencli.py
+++ b/agent_reach/backends/opencli.py
@@ -12,15 +12,13 @@ OPENCLI_EXTENSION_URL = (
f"https://chromewebstore.google.com/detail/opencli/{OPENCLI_EXTENSION_ID}"
)
-_NAV_REJECTED_HINT = (
- "OpenCLI's browser extension could not open the page. This is a known open "
- "OpenCLI issue on recent Chrome (github.com/jackwener/opencli/issues/2487); "
- "retrying a few seconds later sometimes works. Do not retry in a loop."
-)
-
def _opencli_error(text: str, login_hint: str):
- """Map OpenCLI's YAML error block (printed even with -f json) to a ReachError."""
+ """Turn OpenCLI's YAML error block (printed even with -f json) into a ReachError.
+
+ OpenCLI's own `message` and `help` are passed through unchanged. The code only
+ decides Reach's control flow (stop, pause the channel, try the next backend).
+ """
# Node warnings can precede the upstream YAML envelope on stdout. Parse the
# envelope itself so warnings neither hide error codes nor flood the user.
import re
@@ -41,22 +39,21 @@ def _opencli_error(text: str, login_hint: str):
except yaml.YAMLError:
doc = None
err = (doc or {}).get("error") if isinstance(doc, dict) else None
- code = str((err or {}).get("code", "")).upper()
- message = str((err or {}).get("message", "") or text.strip()[:300] or "OpenCLI failed")[:300]
+ err = err if isinstance(err, dict) else {}
+ code = str(err.get("code", "")).upper()
+ message = str(err.get("message", "") or text.strip() or "OpenCLI failed")[:500]
+ upstream_hint = str(err.get("help") or err.get("hint") or "").strip() or None
low = message.lower()
if any(w in low for w in ("环境异常", "环境存在异常", "browser environment", "captcha", "验证码", "安全验证", "account_risk")) or code in {"ACCOUNT_RISK", "CAPTCHA_REQUIRED"}:
- return ReachError(PLATFORM_BLOCKED, message)
+ return ReachError(PLATFORM_BLOCKED, message, hint=upstream_hint, source="opencli")
if code in {"RATE_LIMITED", "RATE_LIMIT"} or any(w in low for w in ("http 429", "too many requests", "访问过于频繁")):
- return ReachError(RATE_LIMITED, message)
- if re.search(r"\bHTTP 404\b", message, re.I) and code not in {"AUTH_REQUIRED", "LOGIN_REQUIRED"}:
- return ReachError(UPSTREAM_BROKEN, message,
- hint="The upstream route returned HTTP 404. Repeated login will not repair a missing endpoint.")
+ return ReachError(RATE_LIMITED, message, source="opencli")
login_words = ("login", "log in", "logged in", "sign in", "http 401", "登录")
- if "AUTH" in code or "LOGIN" in code or any(w in low for w in login_words):
- return ReachError(NEED_LOGIN, message, hint=login_hint or None)
- if "navigation rejected" in low:
- return ReachError(UPSTREAM_BROKEN, message, hint=_NAV_REJECTED_HINT)
- return ReachError(UPSTREAM_BROKEN, f"OpenCLI: {message}")
+ if not re.search(r"\bHTTP 404\b", message, re.I) and (
+ "AUTH" in code or "LOGIN" in code or any(w in low for w in login_words)):
+ # Upstream would send the user to their own Chrome; Reach logs in in its own browser.
+ return ReachError(NEED_LOGIN, message, hint=login_hint or None, source="opencli")
+ return ReachError(UPSTREAM_BROKEN, message, hint=upstream_hint, source="opencli")
def opencli_call(site: str, args, *, timeout: float, login_hint: str = ""):
diff --git a/agent_reach/channels/_opencli_site.py b/agent_reach/channels/_opencli_site.py
index c9d394d8..365ca21d 100644
--- a/agent_reach/channels/_opencli_site.py
+++ b/agent_reach/channels/_opencli_site.py
@@ -40,7 +40,7 @@ class OpenCLISiteChannel(Channel):
try:
items = opencli_items(opencli_call(self.site, list(args), timeout=timeout, login_hint=hint))
if not items and empty_is_error:
- raise ReachError(UPSTREAM_BROKEN, "OpenCLI returned nothing; the page most likely did not load")
+ raise ReachError(UPSTREAM_BROKEN, "OpenCLI finished but returned no items")
except ReachError as err:
if err.code == UPSTREAM_BROKEN and self._logged_out():
raise ReachError(NEED_LOGIN, f"Not logged in to {self.login_hint}", hint=hint) from None
diff --git a/agent_reach/channels/bilibili.py b/agent_reach/channels/bilibili.py
index 26d7d0b4..037e926f 100644
--- a/agent_reach/channels/bilibili.py
+++ b/agent_reach/channels/bilibili.py
@@ -68,16 +68,17 @@ def _bili_json(args: list, timeout: float) -> Any:
if not payload.get("ok"):
err = payload.get("error") or {}
code = str(err.get("code", ""))
- message = str(err.get("message", "bili-cli failed"))[:300]
+ message = str(err.get("message", "bili-cli failed"))[:500]
+ upstream_hint = str(err.get("hint") or "").strip() or None
if any(word in code.lower() for word in ("risk", "captcha", "verification")):
- raise ReachError(PLATFORM_BLOCKED, message)
+ raise ReachError(PLATFORM_BLOCKED, message, hint=upstream_hint, source="bili-cli")
if "rate" in code.lower() or "频繁" in message:
- raise ReachError(RATE_LIMITED, message)
+ raise ReachError(RATE_LIMITED, message, source="bili-cli")
if code == "not_found":
- raise ReachError(NOT_FOUND, message)
+ raise ReachError(NOT_FOUND, message, source="bili-cli")
if "login" in code or "auth" in code or "credential" in code:
- raise ReachError(NEED_LOGIN, message, hint=_BILI_LOGIN_HINT)
- raise ReachError(UPSTREAM_BROKEN, message)
+ raise ReachError(NEED_LOGIN, message, hint=_BILI_LOGIN_HINT, source="bili-cli")
+ raise ReachError(UPSTREAM_BROKEN, message, hint=upstream_hint, source="bili-cli")
return payload.get("data") or {}
diff --git a/agent_reach/runtime/result.py b/agent_reach/runtime/result.py
index d2323af6..f378e78d 100644
--- a/agent_reach/runtime/result.py
+++ b/agent_reach/runtime/result.py
@@ -37,7 +37,7 @@ DEFAULT_HINTS = {
PLATFORM_BLOCKED: "Stop automation. Keep this profile; the user must resolve the platform verification in the official page. Do not switch backends or retry.",
NEED_SETUP: "This backend is not installed. Ask the user to run `agent-reach doctor` for setup steps.",
NEED_LOGIN: "The attempted saved/local session did not grant access. Offer site-scoped local reuse or let the user log in themselves; never ask for a password.",
- UPSTREAM_BROKEN: "The upstream tool failed. Offer one update from the same installation source after user approval; never update automatically or retry in a loop.",
+ UPSTREAM_BROKEN: "The upstream tool failed; `message` is its own wording. Tell the user what it says; do not retry in a loop, and suggest `agent-reach update` only if the message points to an outdated tool.",
TIMEOUT: "The operation timed out. Inspect channel status and the failed stage; do not reopen login windows or repeat requests in a loop.",
RATE_LIMITED: "The platform reported a rate limit. Reach pauses this channel; respect retry_after_seconds and do not switch backends.",
NOT_FOUND: "The requested content does not exist. Check the link or id.",
@@ -48,13 +48,15 @@ _MAX_MESSAGE_CHARS = 500
class ReachError(Exception):
- """An upstream failure already mapped to a unified error code."""
+ """A failure with a unified code. `source` names who wrote `message`/`hint`:
+ an upstream tool (passed through unchanged) or None for Agent Reach itself."""
- def __init__(self, code: str, message: str, hint: Optional[str] = None):
+ def __init__(self, code: str, message: str, hint: Optional[str] = None, source: Optional[str] = None):
super().__init__(message)
self.code = code
self.message = message
self.hint = hint
+ self.source = source
def _clean(text: object) -> str:
@@ -138,5 +140,6 @@ def envelope(
"code": error.code,
"message": error.message,
"hint": error.hint or DEFAULT_HINTS.get(error.code, ""),
+ "source": getattr(error, "source", None) or "agent-reach",
},
}
diff --git a/agent_reach/skill/SKILL.md b/agent_reach/skill/SKILL.md
index ae087e77..45332fa3 100644
--- a/agent_reach/skill/SKILL.md
+++ b/agent_reach/skill/SKILL.md
@@ -42,7 +42,7 @@ agent-reach read <链接> # 按链接自动选渠道
|---|---|
| `NEED_SETUP` | 缺依赖或密钥。按提示 `agent-reach add <渠道>`;要密钥时请用户本人提供,再 `agent-reach configure <key>` |
| `NEED_LOGIN` | 保留已有结果,告诉用户需要登录;`agent-reach login <渠道>` 打开浏览器,由用户本人登录,你绝不代登、不要密码 |
-| `UPSTREAM_BROKEN` | 上游工具坏了。说明情况,用户同意后跑一次 `agent-reach update`;不循环重试 |
+| `UPSTREAM_BROKEN` | 上游工具出错,`message` 是它的原话(`source` 写着是哪个工具)。把原话的意思告诉用户;原话说明工具过时,才在用户同意后跑一次 `agent-reach update`;不循环重试 |
| `TIMEOUT` | 看失败阶段和渠道状态(`agent-reach doctor --text`);不反复重试、不反复开窗 |
| `RATE_LIMITED` | 平台限流,Reach 已暂停该渠道;按 `retry_after_seconds` 等,不换后端 |
| `PLATFORM_BLOCKED` | 平台要求验证(验证码/风控)。停下,请用户在官方页面处理;不换账号、不换后端 |
diff --git a/agent_reach/skill/SKILL_en.md b/agent_reach/skill/SKILL_en.md
index 0099b616..2ba86a1f 100644
--- a/agent_reach/skill/SKILL_en.md
+++ b/agent_reach/skill/SKILL_en.md
@@ -43,7 +43,7 @@ agent-reach read <url> # picks the channel from the URL
|---|---|
| `NEED_SETUP` | Missing dependency or key. Run `agent-reach add <channel>` as hinted; for a key, the user provides it, then `agent-reach configure <key>` |
| `NEED_LOGIN` | Keep existing results and tell the user login is needed; `agent-reach login <channel>` opens the browser and the user logs in themselves. Never log in for them or ask for a password |
-| `UPSTREAM_BROKEN` | The upstream tool failed. Explain, and after the user agrees run `agent-reach update` once; never retry in a loop |
+| `UPSTREAM_BROKEN` | The upstream tool failed; `message` is its own wording (`source` names the tool). Tell the user what it says; run `agent-reach update` once, after they agree, only if the message points to an outdated tool; never retry in a loop |
| `TIMEOUT` | Check the failed stage and channel status (`agent-reach doctor --text`); do not retry or reopen windows in a loop |
| `RATE_LIMITED` | The platform rate-limited; Reach paused the channel. Wait `retry_after_seconds`; do not switch backends |
| `PLATFORM_BLOCKED` | The platform wants verification (captcha/risk check). Stop; the user resolves it on the official page. Do not switch accounts or backends |
diff --git a/tests/test_unified_entry.py b/tests/test_unified_entry.py
index fbbd3f42..7dde709e 100644
--- a/tests/test_unified_entry.py
+++ b/tests/test_unified_entry.py
@@ -619,6 +619,26 @@ def test_opencli_errors_map_to_unified_codes(yaml_text, code):
assert _opencli_error(yaml_text, "").code == code
+def test_opencli_message_and_help_reach_the_agent_unchanged():
+ from agent_reach.backends.opencli import _opencli_error
+ from agent_reach.runtime.result import envelope
+
+ text = ("node warning\nok: false\nerror:\n code: BROWSER_CONNECT\n"
+ " message: Browser profile \"x\" is not connected\n help: Open the matching Chrome profile.\n")
+ err = _opencli_error(text, "reach login steps")
+ out = envelope(channel="reddit", action="search", error=err)["error"]
+ assert out == {"code": "UPSTREAM_BROKEN", "message": 'Browser profile "x" is not connected',
+ "hint": "Open the matching Chrome profile.", "source": "opencli"}
+ login = _opencli_error("ok: false\nerror:\n code: AUTH_REQUIRED\n message: Not logged into x.com\n"
+ " help: Log in in your Chrome.\n", "reach login steps")
+ assert login.message == "Not logged into x.com" and login.hint == "reach login steps" # Reach's own browser
+
+
+def test_reach_own_errors_say_so():
+ from agent_reach.runtime.result import ReachError, envelope
+ assert envelope(channel=None, action=None, error=ReachError("BUSY", "full"))["error"]["source"] == "agent-reach"
+
+
def test_query_uses_an_open_login_window_without_closing_it(fake_browser):
from agent_reach.runtime import browser
browser.setup()