Give your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
Python agent-infrastructureai-agentai-searchautomationbilibiliclaude-codeclicursorfree-apillm-toolsmcppythonreddit-scrapertwitter-scraperweb-scraperxiaohongshuyoutube-transcript
fix(types): unify all os.name guards to sys.platform; add Windows SIGTERM fallback
Ricardo Lauritoa4aafd697054
diff --git a/agent_reach/channels/bilibili.py b/agent_reach/channels/bilibili.pyindex fa88ebba..2aa71d0a 100644--- a/agent_reach/channels/bilibili.py+++ b/agent_reach/channels/bilibili.py@@ -12,6 +12,7 @@ YouTube backend; it just no longer serves bilibili.import jsonimport reimport urllib.request+from typing import Anyfrom agent_reach.runtime.result import (BAD_INPUT,@@ -50,7 +51,7 @@ def _bvid(target: str, timeout: float) -> str:raise ReachError(BAD_INPUT, "target must be a BV id or a bilibili.com / b23.tv video link")-def _bili_json(args: list, timeout: float): # returns dict or list depending on the subcommand+def _bili_json(args: list, timeout: float) -> Any:"""Run bili-cli with --json; map its error envelope to unified codes."""try:out = run_cmd(["bili", *args, "--json"], timeout=timeout, env=session_env("bili-cli"))diff --git a/agent_reach/config.py b/agent_reach/config.pyindex 510b5746..b63efd6b 100644--- a/agent_reach/config.py+++ b/agent_reach/config.py@@ -7,6 +7,7 @@ directories; the private directory is created only on the first write.import osimport stat+import sysimport tempfilefrom pathlib import Pathfrom typing import Any, Optional@@ -58,7 +59,7 @@ def _atomic_write_yaml(target: Path, data: dict) -> None:)tmp_path = Path(tmp_name)try:- if os.name != "nt" and hasattr(os, "fchmod"):+ if sys.platform != "win32" and hasattr(os, "fchmod"):os.fchmod(fd, stat.S_IRUSR | stat.S_IWUSR)with os.fdopen(fd, "w", encoding="utf-8") as handle:yaml.safe_dump(@@ -75,11 +76,11 @@ def _atomic_write_yaml(target: Path, data: dict) -> None:# never follows the symlink into its target._reject_symlink(target, "配置文件")os.replace(tmp_path, target)- if os.name != "nt":+ if sys.platform != "win32":os.chmod(target, stat.S_IRUSR | stat.S_IWUSR)# Persist the rename where directory fsync is supported.- if os.name != "nt" and hasattr(os, "O_DIRECTORY"):+ if sys.platform != "win32" and hasattr(os, "O_DIRECTORY"):try:dir_fd = os.open(target.parent, os.O_RDONLY | os.O_DIRECTORY)try:diff --git a/agent_reach/runtime/browser.py b/agent_reach/runtime/browser.pyindex b7c56fd1..e6a9aae0 100644--- a/agent_reach/runtime/browser.py+++ b/agent_reach/runtime/browser.py@@ -356,7 +356,7 @@ def ensure_chrome() -> str:def can_load_extension() -> bool:"""macOS/Linux: the watcher loads the extension over the launch pipe. Windows: Web Store only."""- return os.name != "nt"+ return sys.platform != "win32"def chrome_argv(exe: str, url: str, *, pipe: bool) -> List[str]:@@ -450,7 +450,7 @@ def _detach_kwargs() -> dict:# agent_reach/ folder where the user ran the command would shadow the installed package.root = browser_root()make_private_dir(root)- if os.name == "nt":+ if sys.platform == "win32":return {"cwd": str(root), "creationflags": subprocess.DETACHED_PROCESS| subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.CREATE_NO_WINDOW}return {"cwd": str(root), "start_new_session": True}@@ -586,7 +586,7 @@ def open_url(url: str) -> None:def _profile_pids() -> List[int]:"""Processes started with our --user-data-dir (Chrome and its helpers)."""- if os.name == "nt":+ if sys.platform == "win32":return []try:out = subprocess.run(["ps", "-axww", "-o", "pid=,command="], capture_output=True, text=True, timeout=10).stdout@@ -638,6 +638,8 @@ def delete_profile() -> bool:with contextlib.suppress(OSError):if sys.platform != "win32":os.kill(pid, signal.SIGKILL)+ else:+ os.kill(pid, signal.SIGTERM)wait_for(lambda: not watcher_running(), 20.0, interval=0.2)shutil.rmtree(root, ignore_errors=True)return not root.exists()diff --git a/agent_reach/runtime/run.py b/agent_reach/runtime/run.pyindex b39f6754..83d8239f 100644--- a/agent_reach/runtime/run.py+++ b/agent_reach/runtime/run.py@@ -56,7 +56,7 @@ def run_cmd(stdin=subprocess.DEVNULL,env=run_env,cwd=cwd or os.path.expanduser("~"),- start_new_session=(os.name != "nt"),+ start_new_session=(sys.platform != "win32"),)try:out, err = proc.communicate(timeout=max(timeout, 0.1))diff --git a/agent_reach/runtime/tools.py b/agent_reach/runtime/tools.pyindex d1e9555b..63bcf081 100644--- a/agent_reach/runtime/tools.py+++ b/agent_reach/runtime/tools.py@@ -71,7 +71,7 @@ TOOLS: Dict[str, Tool] = {_BY_COMMAND = {c: t for t in TOOLS.values() for c in t.commands}_SAFE_NAME = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]*$")-_WIN = os.name == "nt"+_WIN = sys.platform == "win32"def tools_root() -> Path:diff --git a/agent_reach/runtime/update_notice.py b/agent_reach/runtime/update_notice.pyindex d1f2e1b3..3311d5b5 100644--- a/agent_reach/runtime/update_notice.py+++ b/agent_reach/runtime/update_notice.py@@ -104,7 +104,7 @@ def maybe_refresh() -> None:started_path().touch()kwargs: dict = {"stdin": subprocess.DEVNULL, "stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL,"close_fds": True, "cwd": str(state.root())}- if os.name == "nt":+ if sys.platform == "win32":kwargs["creationflags"] = subprocess.DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUPelse:kwargs["start_new_session"] = Truediff --git a/agent_reach/utils/paths.py b/agent_reach/utils/paths.pyindex 43cc17c7..99d623c7 100644--- a/agent_reach/utils/paths.py+++ b/agent_reach/utils/paths.py@@ -75,7 +75,7 @@ def _replace(src: Path, dst: Path) -> None:os.replace(src, dst)returnexcept PermissionError:- if os.name != "nt" or attempt == 19:+ if sys.platform != "win32" or attempt == 19:raisetime.sleep(0.05)@@ -107,7 +107,7 @@ def atomic_write_private_text()tmp_path = Path(tmp_name)try:- if os.name != "nt" and hasattr(os, "fchmod"):+ if sys.platform != "win32" and hasattr(os, "fchmod"):os.fchmod(fd, stat.S_IRUSR | stat.S_IWUSR)handle = os.fdopen(fd, "w", encoding=encoding)fd = -1@@ -120,7 +120,7 @@ def atomic_write_private_text(ensure_no_symlink_path(target, "目标文件")_replace(tmp_path, target)- if os.name != "nt" and hasattr(os, "O_DIRECTORY"):+ if sys.platform != "win32" and hasattr(os, "O_DIRECTORY"):try:dir_fd = os.open(parent,