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: ask to log in again only when a login that worked has expired

Pnant02ebf305d4dd
diff --git a/agent_reach/runtime/manage.py b/agent_reach/runtime/manage.py
index 4722557d..aa4a3d2d 100644
--- a/agent_reach/runtime/manage.py
+++ b/agent_reach/runtime/manage.py
@@ -659,7 +659,9 @@ def sync() -> dict:
actions.append(_sentence(f"{c.name}: {err.hint or err.message}"))
actions += [_sentence(f"{c.name}: {p}") for p in c.setup_problems()]
check = data["checks"].get(c.name) or {}
- if "NEED_LOGIN" in (check.get("codes") or {}).values():
+ previous = check.get("previous") or {}
+ expired = [a for a, code in (check.get("codes") or {}).items() if code == "NEED_LOGIN" and previous.get(a)]
+ if expired:
actions.append(f"The user needs to log in to {c.name} again: run `agent-reach login {c.name}`.")
return {"version": __version__, "tools": synced, "problems": problems, "removed_tools": _prune(state.load()),
"dropped_channels": dropped, "user_actions": actions, "skill": place_skill(), "migration": migration}
diff --git a/tests/test_manage.py b/tests/test_manage.py
index f7f86461..2f8bfc9e 100644
--- a/tests/test_manage.py
+++ b/tests/test_manage.py
@@ -280,7 +280,8 @@ def test_sync_upgrades_prunes_drops_and_reports(env):
data["tools"]["old-tool"] = {"owner": "agent-reach", "scope": "private", "version": "0.1.0"}
data["tools"]["user-thing"] = {"owner": "user", "scope": "global", "version": "1.0.0"}
data["channels"]["gone"] = {"added_at": "2026-01-01T00:00:00Z"}
- data["checks"]["bili"] = {"at": state.now(), "actions": {"search": False}, "codes": {"search": "NEED_LOGIN"}}
+ data["checks"]["bili"] = {"at": state.now(), "actions": {"search": False}, "codes": {"search": "NEED_LOGIN"},
+ "previous": {"search": True}}
state.save(data)
(tools.tool_dir("old-tool") / "bin").mkdir(parents=True)
env["versions"]["bili-cli"] = "2.0.0"
@@ -291,7 +292,16 @@ def test_sync_upgrades_prunes_drops_and_reports(env):
assert env["installs"].count("bili-cli") == 2, "shared tools upgrade once per sync"
assert out["dropped_channels"] == ["gone"] and "gone" not in state.load()["channels"]
assert any("gone" in a for a in out["user_actions"])
- assert any("log in to bili" in a for a in out["user_actions"])
+ assert any("log in to bili" in a for a in out["user_actions"]), "a login that worked before and now fails"
+
+
+def test_sync_does_not_ask_to_log_in_again_when_never_logged_in(env):
+ manage.add("bili")
+ data = state.load()
+ data["checks"]["bili"] = {"at": state.now(), "actions": {"search": False}, "codes": {"search": "NEED_LOGIN"},
+ "previous": {}}
+ state.save(data)
+ assert not any("log in" in a for a in manage.sync()["user_actions"])
@pytest.mark.parametrize("latest, available", [("v2.0.1", True), ("v2.0.0", False), ("v1.9.9", False)])