Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

feat(grounding): keyless web search floor, host-gated (U2)

Matt Van Horne8187a36da09
diff --git a/CONFIGURATION.md b/CONFIGURATION.md
index 77628a9f..2031d51b 100644
--- a/CONFIGURATION.md
+++ b/CONFIGURATION.md
@@ -158,15 +158,22 @@ When you invoke `/last30days` from Claude Code, Codex, or Gemini, the host model
## Web search backend priority
-Used by `--auto-resolve` (when WebSearch isn't available from the host) and Step 2 supplements. Auto-detect priority (override per-run with `--web-backend=<name>`):
+The search-source preference ladder, strict best-to-floor:
-1. **Brave** - `BRAVE_API_KEY`
-2. **Exa** - `EXA_API_KEY`
-3. **Serper** - `SERPER_API_KEY`
-4. **Parallel** - `PARALLEL_API_KEY`
-5. **Host's native WebSearch** - Claude Code, Codex, Gemini all have one built in
+1. **Host-native search** - Claude Code's `WebSearch`, and the equivalents on Codex / Gemini. Best results; used automatically on hosts that have it. Signalled to the engine via `LAST30DAYS_NATIVE_SEARCH=1` (the skill sets this for you when your host has a native search tool) so the engine does not run a worse search underneath it.
+2. **Paid engine backend** - one of `BRAVE_API_KEY`, `EXA_API_KEY`, `SERPER_API_KEY`, `PARALLEL_API_KEY`, auto-detected in that order. Override per-run with `--web-backend=<name>`.
+3. **Keyless engine floor** - zero-key web search (DuckDuckGo, plus an optional SearXNG instance) and zero-key page fetch (Jina Reader). Runs only when the host has **no** native search **and** no paid key is set, so headless/cron and hosts without a built-in search tool still get general-web coverage. Force it explicitly with `--web-backend=keyless`.
-Visible quality difference between hosts with vs without a configured backend. If your client setup produces thinner results than yours, this is usually why.
+Relevant env vars:
+
+| Var | Effect |
+| --- | --- |
+| `LAST30DAYS_NATIVE_SEARCH=1` | Tells the engine your host has native search; suppresses the keyless floor. Set automatically by the skill on capable hosts. Leave unset on hosts without a native search tool so the floor runs. |
+| `LAST30DAYS_SEARXNG_URL=<base-url>` | Optional. A SearXNG instance used as the keyless-search fallback rung when DuckDuckGo returns nothing. |
+
+Privacy note: the keyless floor sends the query (to DuckDuckGo / your SearXNG instance) and any fetched URL (to Jina Reader) to those third parties. It is intended for public-research use; results may be cached snapshots. It never runs when native search or a paid backend is in play.
+
+Visible quality difference between hosts with vs without native search or a configured backend. If your client setup produces thinner results than yours, this is usually why.
---
diff --git a/skills/last30days/SKILL.md b/skills/last30days/SKILL.md
index 750cb219..95c9b79b 100644
--- a/skills/last30days/SKILL.md
+++ b/skills/last30days/SKILL.md
@@ -270,6 +270,14 @@ fi
LAST30DAYS_MEMORY_DIR="${LAST30DAYS_MEMORY_DIR:-$HOME/Documents/Last30Days}"
```
+**Native-search signal (web coverage).** If you (the hosting model) have your own web-search tool available — e.g. Claude Code's `WebSearch`, which STEP 0 loads — export `LAST30DAYS_NATIVE_SEARCH=1` in the same shell before invoking the engine:
+
+```bash
+export LAST30DAYS_NATIVE_SEARCH=1 # ONLY when you have a native web-search tool
+```
+
+Your native search is better than the engine's keyless web fallback, so this tells the engine to skip that fallback and leave general web to you (you already run WebSearch supplements in Step 2). If you have NO native web-search tool (some non-Claude hosts and headless/cron paths), do **not** set this: the engine's keyless web floor supplies general-web coverage automatically. The rule is capability-based, not host-name-based — set it only when you genuinely have a better search, never to suppress the floor on a host that has nothing else.
+
## Configuration
Set `LAST30DAYS_MEMORY_DIR` before invoking the skill to choose where raw research files are saved. If it is not set, the skill defaults to `~/Documents/Last30Days`.
diff --git a/skills/last30days/scripts/lib/env.py b/skills/last30days/scripts/lib/env.py
index 1521c3ce..4a16c6e9 100644
--- a/skills/last30days/scripts/lib/env.py
+++ b/skills/last30days/scripts/lib/env.py
@@ -395,6 +395,12 @@ def get_config() -> dict[str, Any]:
('OPENROUTER_API_KEY', None),
('PARALLEL_API_KEY', None),
('XQUIK_API_KEY', None),
+ # Host-native search signal: set by the SKILL.md agent-host path when the
+ # invoking runtime has its own (better) web-search tool, so the engine's
+ # keyless search floor stays off there. Defaults unset -> floor allowed.
+ ('LAST30DAYS_NATIVE_SEARCH', None),
+ # Optional SearXNG instance for the keyless-search fallback rung.
+ ('LAST30DAYS_SEARXNG_URL', None),
('FROM_BROWSER', None),
('SETUP_COMPLETE', None),
('INCLUDE_SOURCES', ''),
@@ -633,6 +639,32 @@ def is_hackernews_available() -> bool:
return True
+def is_native_search(config: dict[str, Any]) -> bool:
+ """Whether the invoking host has its own (better) native web search.
+
+ Defined by capability, not host identity: the SKILL.md agent-host path sets
+ ``LAST30DAYS_NATIVE_SEARCH`` when the runtime actually has a native web-search
+ tool (e.g. Claude Code's WebSearch). When true, the engine's keyless search
+ floor is suppressed so a worse free search never preempts the model's own.
+ Defaults False (unset), so headless/cron and hosts without native search fall
+ to the keyless floor.
+ """
+ raw = config.get('LAST30DAYS_NATIVE_SEARCH')
+ if raw is None:
+ return False
+ return str(raw).strip().lower() in ('1', 'true', 'yes', 'on')
+
+
+def keyless_web_allowed(config: dict[str, Any]) -> bool:
+ """Whether the engine may use its keyless web-search floor for this run.
+
+ Allowed only when the host does NOT have native search. Independent of
+ whether a paid key is set (the grounding dispatcher prefers paid first and
+ falls to keyless on empty/error for non-native runs).
+ """
+ return not is_native_search(config)
+
+
def is_bluesky_available(config: dict[str, Any]) -> bool:
"""Check if Bluesky source is available.
diff --git a/skills/last30days/scripts/lib/grounding.py b/skills/last30days/scripts/lib/grounding.py
index 6bab2d76..c3ae7f70 100644
--- a/skills/last30days/scripts/lib/grounding.py
+++ b/skills/last30days/scripts/lib/grounding.py
@@ -1,4 +1,4 @@
-"""Web search retrieval via Brave Search, Exa, and Serper."""
+"""Web search retrieval via Brave Search, Exa, Serper, Parallel, or a keyless floor."""
from __future__ import annotations
@@ -7,7 +7,7 @@ import urllib.parse
from datetime import datetime
from urllib.parse import urlparse
-from . import dates, http
+from . import dates, env, http, web_search_keyless
# ---------------------------------------------------------------------------
@@ -207,6 +207,11 @@ def web_search(
backend = "serper"
elif config.get("PARALLEL_API_KEY"):
backend = "parallel"
+ elif env.keyless_web_allowed(config):
+ # No paid key and the host has no native search -> use the keyless
+ # floor. On a native-search host this branch is skipped (the model
+ # supplies web results itself), so the engine returns nothing here.
+ backend = "keyless"
else:
return [], {}
items: list[dict] = []
@@ -231,6 +236,8 @@ def web_search(
if not key:
raise RuntimeError("PARALLEL_API_KEY is required when web_backend='parallel'")
items, artifact = parallel_search(query, date_range, key)
+ elif backend == "keyless":
+ items, artifact = web_search_keyless.keyless_search(query, date_range, config)
elif backend != "none":
raise ValueError(f"Unsupported web backend: {backend!r}")
else:
diff --git a/skills/last30days/scripts/lib/pipeline.py b/skills/last30days/scripts/lib/pipeline.py
index a7ae91d8..c80ab8fb 100644
--- a/skills/last30days/scripts/lib/pipeline.py
+++ b/skills/last30days/scripts/lib/pipeline.py
@@ -120,7 +120,13 @@ def available_sources(config: dict[str, Any], requested_sources: list[str] | Non
available.append("bluesky")
if env.is_truthsocial_available(config):
available.append("truthsocial")
- if config.get("BRAVE_API_KEY") or config.get("EXA_API_KEY") or config.get("SERPER_API_KEY") or config.get("PARALLEL_API_KEY"):
+ # Grounding (general web) is available when a paid backend is configured OR
+ # the keyless floor is permitted (i.e. the host has no native search). On a
+ # native-search host with no paid key, keyless_web_allowed is False and the
+ # engine leaves general web to the model's own search.
+ if (config.get("BRAVE_API_KEY") or config.get("EXA_API_KEY")
+ or config.get("SERPER_API_KEY") or config.get("PARALLEL_API_KEY")
+ or env.keyless_web_allowed(config)):
available.append("grounding")
if requested_sources and "jobs" in requested_sources:
available.append("jobs")
@@ -216,7 +222,7 @@ def run(
available = [source for source in available if source in requested_sources]
if web_backend == "none":
available = [s for s in available if s != "grounding"]
- elif web_backend in ("brave", "exa", "serper", "parallel") and "grounding" not in available:
+ elif web_backend in ("brave", "exa", "serper", "parallel", "keyless") and "grounding" not in available:
available.append("grounding")
if (hiring_signals_mode or _company_topic_likely(topic)) and "jobs" not in available:
available.append("jobs")
diff --git a/skills/last30days/scripts/lib/web_search_keyless.py b/skills/last30days/scripts/lib/web_search_keyless.py
new file mode 100644
index 00000000..f5363d4c
--- /dev/null
+++ b/skills/last30days/scripts/lib/web_search_keyless.py
@@ -0,0 +1,153 @@
+"""Keyless web search (floor tier for engine-side general web).
+
+Returns ranked web results for a query with no API key. This is strictly the
+FLOOR of the search-source ladder:
+
+ host-native search > paid engine backend > keyless engine search
+
+It must never run on a host that has native search (the model does it better
+there) or preempt a configured paid backend. The pipeline/grounding layer owns
+that gating; this module just performs the search when asked.
+
+Two vendor-neutral rungs, both stdlib-only via :mod:`http`:
+ 1. DuckDuckGo HTML endpoint (no key, no instance to maintain).
+ 2. A configurable SearXNG instance returning JSON (``LAST30DAYS_SEARXNG_URL``),
+ tried when the primary yields nothing.
+
+Never raises. Returns results in the same dict shape as the paid backends in
+:mod:`grounding` so they flow through normalize/score/dedupe unchanged. On total
+failure returns ``([], artifact)`` with a degraded reason in the artifact, so the
+source-health layer can report it.
+"""
+
+from __future__ import annotations
+
+import html
+import re
+from urllib.parse import parse_qs, urlparse
+
+from . import http
+
+KEYLESS_BACKEND = "keyless"
+
+_DDG_HTML_URL = "https://html.duckduckgo.com/html/"
+
+# Floor-tier relevance: below the paid backends' 0.8 so fusion prefers paid/native
+# results when both are present.
+_KEYLESS_RELEVANCE = 0.6
+
+_TAG_RE = re.compile(r"<[^>]+>")
+_RESULT_A_RE = re.compile(
+ r'class="result__a"[^>]*href="(?P<href>[^"]+)"[^>]*>(?P<title>.*?)</a>',
+ re.IGNORECASE | re.DOTALL,
+)
+_SNIPPET_RE = re.compile(
+ r'class="result__snippet"[^>]*>(?P<snippet>.*?)</a>',
+ re.IGNORECASE | re.DOTALL,
+)
+
+
+def _domain(url: str) -> str:
+ try:
+ return urlparse(url).netloc
+ except (ValueError, AttributeError):
+ return ""
+
+
+def _strip_html(fragment: str) -> str:
+ return html.unescape(_TAG_RE.sub("", fragment or "")).strip()
+
+
+def _unwrap_ddg_redirect(href: str) -> str:
+ """DuckDuckGo wraps result links as //duckduckgo.com/l/?uddg=<encoded>."""
+ if "uddg=" not in href:
+ return href if href.startswith("http") else f"https:{href}" if href.startswith("//") else href
+ try:
+ query = urlparse(href if href.startswith("http") else f"https:{href}").query
+ target = parse_qs(query).get("uddg", [""])[0]
+ return target or href
+ except (ValueError, AttributeError):
+ return href
+
+
+def keyless_search(
+ query: str,
+ date_range: tuple[str, str],
+ config: dict,
+ count: int = 5,
+) -> tuple[list[dict], dict]:
+ """Run keyless web search; returns (items, artifact). Never raises."""
+ items = _search_ddg(query, count)
+ used = "ddg"
+ if not items:
+ searxng_url = (config.get("LAST30DAYS_SEARXNG_URL") or "").strip()
+ if searxng_url:
+ items = _search_searxng(query, count, searxng_url)
+ used = "searxng"
+ artifact = {
+ "label": "keyless",
+ "webSearchQueries": [query],
+ "resultCount": len(items),
+ "keyless_backend": used,
+ }
+ if not items:
+ artifact["reason"] = "keyless-search-unavailable"
+ return items, artifact
+
+
+def _search_ddg(query: str, count: int) -> list[dict]:
+ from urllib.parse import urlencode
+
+ url = f"{_DDG_HTML_URL}?{urlencode({'q': query})}"
+ text = http.get_text(url, accept="text/html", retries=2)
+ if not text:
+ return []
+ items: list[dict] = []
+ snippets = _SNIPPET_RE.findall(text)
+ for i, match in enumerate(_RESULT_A_RE.finditer(text)):
+ if len(items) >= count:
+ break
+ target = _unwrap_ddg_redirect(match.group("href"))
+ if not target.startswith("http"):
+ continue
+ title = _strip_html(match.group("title"))
+ snippet = _strip_html(snippets[i]) if i < len(snippets) else ""
+ items.append(_to_item(i, title, target, snippet))
+ return items
+
+
+def _search_searxng(query: str, count: int, instance_url: str) -> list[dict]:
+ base = instance_url.rstrip("/")
+ from urllib.parse import urlencode
+
+ url = f"{base}/search?{urlencode({'q': query, 'format': 'json'})}"
+ try:
+ data = http.get(url, headers={"Accept": "application/json"}, timeout=15, retries=2)
+ except http.HTTPError:
+ return []
+ if not isinstance(data, dict):
+ return []
+ items: list[dict] = []
+ for i, r in enumerate(data.get("results", [])):
+ if len(items) >= count:
+ break
+ if not isinstance(r, dict):
+ continue
+ target = r.get("url", "")
+ if not target.startswith("http"):
+ continue
+ items.append(_to_item(i, r.get("title", ""), target, r.get("content", "")))
+ return items
+
+
+def _to_item(index: int, title: str, url: str, snippet: str) -> dict:
+ return {
+ "id": f"WK{index + 1}",
+ "title": title,
+ "url": url,
+ "source_domain": _domain(url),
+ "snippet": (snippet or "")[:500],
+ "date": None,
+ "relevance": _KEYLESS_RELEVANCE,
+ "why_relevant": "Keyless web search",
+ }
diff --git a/tests/test_grounding_v3.py b/tests/test_grounding_v3.py
index e4ad23d1..26aa2a21 100644
--- a/tests/test_grounding_v3.py
+++ b/tests/test_grounding_v3.py
@@ -191,11 +191,27 @@ class WebSearchDispatchTests(unittest.TestCase):
grounding.web_search("test", ("2026-02-25", "2026-03-27"), config, backend="auto")
mock.assert_called_once()
- def test_auto_returns_empty_when_no_keys(self):
- items, artifact = grounding.web_search("test", ("2026-02-25", "2026-03-27"), {}, backend="auto")
+ def test_auto_returns_empty_when_no_keys_and_native_search(self):
+ # On a native-search host (signal set) with no paid key, the engine
+ # leaves general web to the model's own search and returns nothing.
+ config = {"LAST30DAYS_NATIVE_SEARCH": "1"}
+ items, artifact = grounding.web_search("test", ("2026-02-25", "2026-03-27"), config, backend="auto")
self.assertEqual([], items)
self.assertEqual({}, artifact)
+ def test_auto_falls_to_keyless_when_no_keys_and_no_native_search(self):
+ # No paid key and no native search -> keyless floor is used.
+ with patch("lib.grounding.web_search_keyless.keyless_search",
+ return_value=([], {"label": "keyless"})) as mock_keyless:
+ grounding.web_search("test", ("2026-02-25", "2026-03-27"), {}, backend="auto")
+ mock_keyless.assert_called_once()
+
+ def test_explicit_keyless_backend_invokes_keyless(self):
+ with patch("lib.grounding.web_search_keyless.keyless_search",
+ return_value=([], {"label": "keyless"})) as mock_keyless:
+ grounding.web_search("test", ("2026-02-25", "2026-03-27"), {}, backend="keyless")
+ mock_keyless.assert_called_once()
+
def test_none_returns_empty(self):
config = {"BRAVE_API_KEY": "test-key"}
items, artifact = grounding.web_search("test", ("2026-02-25", "2026-03-27"), config, backend="none")
diff --git a/tests/test_pipeline_v3.py b/tests/test_pipeline_v3.py
index 85d9cc03..5d06fedb 100644
--- a/tests/test_pipeline_v3.py
+++ b/tests/test_pipeline_v3.py
@@ -1091,6 +1091,28 @@ class TestExcludeSources(unittest.TestCase):
self.assertIn("reddit", sources)
+class TestKeylessGroundingAvailability(unittest.TestCase):
+ """Grounding (general web) availability is host-aware.
+
+ Non-native hosts get the keyless floor by default; native-search hosts leave
+ general web to the model's own search unless a paid key is configured.
+ """
+
+ def test_grounding_available_without_key_on_non_native_host(self):
+ sources = pipeline.available_sources({})
+ self.assertIn("grounding", sources)
+
+ def test_grounding_suppressed_without_key_on_native_host(self):
+ config = {"LAST30DAYS_NATIVE_SEARCH": "1"}
+ sources = pipeline.available_sources(config)
+ self.assertNotIn("grounding", sources)
+
+ def test_grounding_available_with_paid_key_even_on_native_host(self):
+ config = {"LAST30DAYS_NATIVE_SEARCH": "1", "BRAVE_API_KEY": "k"}
+ sources = pipeline.available_sources(config)
+ self.assertIn("grounding", sources)
+
+
class TestExcludeSourcesEndToEnd(unittest.TestCase):
"""Wiring regression: EXCLUDE_SOURCES from the process environment must
reach available_sources() via env.get_config(). The unit tests above
diff --git a/tests/test_web_search_keyless.py b/tests/test_web_search_keyless.py
new file mode 100644
index 00000000..0cc3bdb4
--- /dev/null
+++ b/tests/test_web_search_keyless.py
@@ -0,0 +1,67 @@
+"""Tests for scripts/lib/web_search_keyless.py — keyless web search floor."""
+
+from unittest import mock
+
+from lib import web_search_keyless
+
+_DDG_HTML = """
+<div class="result">
+ <a rel="nofollow" class="result__a" href="//duckduckgo.com/l/?uddg=https%3A%2F%2Fexample.com%2Fpost&amp;rut=x">First &amp; Best</a>
+ <a class="result__snippet" href="//x">A snippet about the <b>topic</b>.</a>
+</div>
+<div class="result">
+ <a rel="nofollow" class="result__a" href="//duckduckgo.com/l/?uddg=https%3A%2F%2Fnews.example.org%2Fa">Second result</a>
+ <a class="result__snippet" href="//y">Second snippet.</a>
+</div>
+"""
+
+
+class TestKeylessSearch:
+ def test_ddg_parsing_happy_path(self):
+ with mock.patch.object(web_search_keyless.http, "get_text", return_value=_DDG_HTML):
+ items, artifact = web_search_keyless.keyless_search(
+ "topic", ("2026-02-25", "2026-03-27"), {})
+ assert len(items) == 2
+ assert items[0]["url"] == "https://example.com/post"
+ assert items[0]["title"] == "First & Best"
+ assert items[0]["source_domain"] == "example.com"
+ assert "snippet about the topic" in items[0]["snippet"]
+ assert artifact["keyless_backend"] == "ddg"
+ # Floor relevance is below the paid backends' 0.8.
+ assert items[0]["relevance"] < 0.8
+
+ def test_item_shape_matches_grounding_backends(self):
+ with mock.patch.object(web_search_keyless.http, "get_text", return_value=_DDG_HTML):
+ items, _ = web_search_keyless.keyless_search("topic", ("2026-02-25", "2026-03-27"), {})
+ required = {"id", "title", "url", "source_domain", "snippet", "date", "relevance", "why_relevant"}
+ assert required.issubset(items[0].keys())
+
+ def test_count_cap(self):
+ with mock.patch.object(web_search_keyless.http, "get_text", return_value=_DDG_HTML):
+ items, _ = web_search_keyless.keyless_search("topic", ("2026-02-25", "2026-03-27"), {}, count=1)
+ assert len(items) == 1
+
+ def test_ddg_down_no_searxng_returns_degraded(self):
+ with mock.patch.object(web_search_keyless.http, "get_text", return_value=None):
+ items, artifact = web_search_keyless.keyless_search("topic", ("2026-02-25", "2026-03-27"), {})
+ assert items == []
+ assert artifact["reason"] == "keyless-search-unavailable"
+
+ def test_searxng_fallback_when_ddg_empty(self):
+ searxng_payload = {"results": [
+ {"url": "https://searxng.example/a", "title": "SX A", "content": "sx snippet"},
+ ]}
+ with mock.patch.object(web_search_keyless.http, "get_text", return_value=None), \
+ mock.patch.object(web_search_keyless.http, "get", return_value=searxng_payload):
+ items, artifact = web_search_keyless.keyless_search(
+ "topic", ("2026-02-25", "2026-03-27"),
+ {"LAST30DAYS_SEARXNG_URL": "https://searxng.example"})
+ assert len(items) == 1
+ assert items[0]["url"] == "https://searxng.example/a"
+ assert artifact["keyless_backend"] == "searxng"
+
+ def test_skips_non_http_results(self):
+ html = '<a class="result__a" href="//duckduckgo.com/l/?uddg=javascript%3Avoid(0)">bad</a>'
+ with mock.patch.object(web_search_keyless.http, "get_text", return_value=html):
+ items, _ = web_search_keyless.keyless_search("topic", ("2026-02-25", "2026-03-27"), {})
+ assert items == []