The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(web): cache_exempt_hosts — always-live fetches for staging/tunnel sites
Tekniumba9fc55e165b
diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex adcad7f3405..eb48f427afd 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -538,6 +538,14 @@ DEFAULT_CONFIG = {# successful responses are cached."cache_enabled": True,"cache_ttl_minutes": 20,+ # Hosts whose pages must always be fetched live, never from the+ # extract cache — sites you're actively developing but testing over+ # the public internet (staging deploys, tunnel URLs, preview+ # builds). Entries match exactly, as "*.wildcard", or as a domain+ # suffix ("mysite.dev" also covers "preview.mysite.dev").+ # localhost/private-IP URLs are always exempt automatically.+ # cache_exempt_hosts: ["mysite.vercel.app", "*.ngrok-free.app"]+ "cache_exempt_hosts": [],},"browser": {diff --git a/tests/tools/test_web_result_cache.py b/tests/tools/test_web_result_cache.pyindex 94db38651b9..8cb2cf3a23f 100644--- a/tests/tools/test_web_result_cache.py+++ b/tests/tools/test_web_result_cache.py@@ -226,6 +226,56 @@ def test_extract_cache_public_urls_still_cache(url, _isolated_cache):assert hit is not None and hit["content"] == "public content"+class TestCacheExemptHosts:+ """web.cache_exempt_hosts: staging/tunnel sites on public DNS that the+ user is actively developing — always fetched live."""++ def _config(self, monkeypatch, hosts):+ monkeypatch.setattr(+ wrc, "_web_config", lambda: {"cache_exempt_hosts": hosts}+ )++ @pytest.mark.parametrize("pattern,url", [+ ("mysite.vercel.app", "https://mysite.vercel.app/page"),+ ("MYSITE.VERCEL.APP", "https://mysite.vercel.app/page"), # case+ ("*.ngrok-free.app", "https://abc123.ngrok-free.app/"),+ ("mysite.dev", "https://preview.mysite.dev/build/7"), # suffix+ ("mysite.dev", "https://mysite.dev/"), # exact+ ])+ def test_exempt_host_never_cached(self, monkeypatch, _isolated_cache,+ pattern, url):+ self._config(monkeypatch, [pattern])+ extract_cache_put(url, "stale staging build")+ assert extract_cache_get(url) is None++ def test_non_matching_host_still_caches(self, monkeypatch, _isolated_cache):+ self._config(monkeypatch, ["mysite.vercel.app"])+ extract_cache_put("https://docs.python.org/3/", "cached fine")+ assert extract_cache_get("https://docs.python.org/3/") is not None++ def test_suffix_cannot_match_lookalike_domain(self, monkeypatch,+ _isolated_cache):+ """'mysite.dev' must not exempt 'evilmysite.dev' — suffix matching+ is label-boundary aware."""+ self._config(monkeypatch, ["mysite.dev"])+ extract_cache_put("https://evilmysite.dev/x", "content")+ assert extract_cache_get("https://evilmysite.dev/x") is not None++ def test_garbage_config_fails_open_to_caching(self, monkeypatch,+ _isolated_cache):+ self._config(monkeypatch, "not-a-list")+ extract_cache_put("https://example.com/a", "content")+ assert extract_cache_get("https://example.com/a") is not None++ def test_exemption_applies_at_get_time_too(self, monkeypatch,+ _isolated_cache):+ """Adding an exemption mid-TTL takes effect immediately: an entry+ cached before the config change must not be served after it."""+ extract_cache_put("https://mysite.vercel.app/p", "old build")+ self._config(monkeypatch, ["mysite.vercel.app"])+ assert extract_cache_get("https://mysite.vercel.app/p") is None++def test_extract_cache_tampered_index_path_is_miss(_isolated_cache, tmp_path):"""An index entry pointing outside cache/web must never be read."""outside = tmp_path / "outside.md"diff --git a/tools/web_result_cache.py b/tools/web_result_cache.pyindex d5b8371e382..98fe4d763af 100644--- a/tools/web_result_cache.py+++ b/tools/web_result_cache.py@@ -275,6 +275,45 @@ def _entry_file_path(url: str, format: Optional[str], provider: str) -> Optionalreturn d / f"{slug}-{_url_digest(url, format, provider)}.cache.md"+def _host_matches_pattern(host: str, pattern: str) -> bool:+ """Case-insensitive host match: exact, ``*.wildcard``, or bare-domain+ suffix (``mysite.dev`` also matches ``preview.mysite.dev``)."""+ host = host.lower().strip(".")+ pattern = (pattern or "").lower().strip().strip(".")+ if not pattern:+ return False+ if pattern.startswith("*."):+ base = pattern[2:]+ return host == base or host.endswith("." + base)+ return host == pattern or host.endswith("." + pattern)+++def _is_cache_exempt_host(url: str) -> bool:+ """True when the URL's host matches ``web.cache_exempt_hosts``.++ For sites the user is actively developing but testing over the public+ internet (staging deploys, tunnel URLs, preview builds) — public DNS,+ so the local-dev heuristic can't catch them, but every fetch must be+ live. List entries match exactly, as ``*.wildcard``, or as a domain+ suffix.+ """+ try:+ patterns = _web_config().get("cache_exempt_hosts") or []+ if not isinstance(patterns, (list, tuple)):+ return False+ if not patterns:+ return False+ from urllib.parse import urlparse+ host = (urlparse(url).hostname or "").strip("[]")+ if not host:+ return False+ return any(+ _host_matches_pattern(host, str(p)) for p in patterns+ )+ except Exception: # noqa: BLE001 — config problems never break tools+ return False++def _is_local_dev_url(url: str) -> bool:"""True for loopback/private/LAN URLs — never cached.@@ -320,7 +359,7 @@ def extract_cache_get("""Return {'url','title','content'} for a fresh cached page, else None."""if not cache_enabled():return None- if _is_local_dev_url(url):+ if _is_local_dev_url(url) or _is_cache_exempt_host(url):return Nonewith _index_lock:index = _load_index()@@ -366,7 +405,7 @@ def extract_cache_put("""if not cache_enabled() or not content:return- if _is_local_dev_url(url):+ if _is_local_dev_url(url) or _is_cache_exempt_host(url):returntry:from tools.web_tools import MAX_STORED_TEXT_CHARSdiff --git a/website/docs/user-guide/features/web-search.md b/website/docs/user-guide/features/web-search.mdindex a90c69bfab6..ddacf7f4a86 100644--- a/website/docs/user-guide/features/web-search.md+++ b/website/docs/user-guide/features/web-search.md@@ -77,6 +77,16 @@ Only successful responses are cached. Failures always retry the backend, respons**Local development URLs are never cached.** Anything on `localhost`, `127.0.0.1`, `*.local`, single-label LAN hostnames, or private/link-local IP ranges (`192.168.*`, `10.*`, `172.16-31.*`) bypasses the extract cache entirely — dev servers, hot-reload builds, and chat-GUI artifact previews change on every save, and a cached copy would show you a stale build. Every fetch of a local page is live. (These URLs are only reachable at all when `security.allow_private_urls` is enabled.)+**Testing over the public internet?** Staging deploys and tunnel URLs are public DNS, so the local-dev rule can't catch them — list them in `web.cache_exempt_hosts` and they're always fetched live too. Entries match exactly, as a `*.` wildcard, or as a domain suffix (`mysite.dev` also covers `preview.mysite.dev`):++```yaml+# ~/.hermes/config.yaml+web:+ cache_exempt_hosts:+ - mysite.vercel.app+ - "*.ngrok-free.app"+```+```yaml# ~/.hermes/config.yamlweb: