AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
fix(hackernews): avoid unsupported Algolia points filter
Shaan Majid7e21004236a3
diff --git a/skills/last30days/scripts/lib/hackernews.py b/skills/last30days/scripts/lib/hackernews.pyindex 3f68843c..8c826529 100644--- a/skills/last30days/scripts/lib/hackernews.py+++ b/skills/last30days/scripts/lib/hackernews.py@@ -31,6 +31,9 @@ DEPTH_CONFIG = {"deep": 60,}+MIN_STORY_POINTS = 2+HN_OVERFETCH_MULTIPLIER = 2+ENRICH_LIMITS = {"quick": 3,"default": 5,@@ -83,6 +86,7 @@ def search_hackernews(Dict with Algolia response (contains 'hits' list)."""count = DEPTH_CONFIG.get(depth, DEPTH_CONFIG["default"])+ fetch_count = count * HN_OVERFETCH_MULTIPLIERfrom_ts = _date_to_unix(from_date)to_ts = _date_to_unix(to_date) + 86400 # Include the end date@@ -93,14 +97,15 @@ def search_hackernews(core_flat = _flatten_query_for_algolia(core)_log(f"Searching for '{core_flat}' (raw: '{topic}', since {from_date}, count={count})")- # Use relevance-sorted search with minimum engagement filter.+ # Use relevance-sorted search with date filters. Algolia's HN index rejects+ # engagement fields in numericFilters, so points are filtered client-side.# NOTE: restrictSearchableAttributes=title omitted intentionally — it would# miss Ask HN/Show HN threads where the topic appears in the body.params = {"query": core_flat,"tags": "story",- "numericFilters": f"created_at_i>{from_ts},created_at_i<{to_ts},points>2",- "hitsPerPage": str(count),+ "numericFilters": f"created_at_i>{from_ts},created_at_i<{to_ts}",+ "hitsPerPage": str(fetch_count),}# Algolia defaults to AND across query tokens, so a 4-5 word theme query# matches no stories. Mark all-but-the-first token as optional so Algolia@@ -121,7 +126,17 @@ def search_hackernews(_log(f"Search failed: {e}")return {"hits": [], "error": str(e)}- hits = response.get("hits", [])+ raw_hits = response.get("hits", [])+ qualifying_hits = [+ hit for hit in raw_hits+ if (hit.get("points") or 0) > MIN_STORY_POINTS+ ]+ hits = qualifying_hits[:count]+ dropped_low_engagement = len(raw_hits) - len(qualifying_hits)+ if dropped_low_engagement:+ _log(f"Filtered {dropped_low_engagement}/{len(raw_hits)} low-engagement stories")+ if len(hits) != len(raw_hits):+ response = {**response, "hits": hits}_log(f"Found {len(hits)} stories")return responsediff --git a/tests/test_hackernews.py b/tests/test_hackernews.pyindex 3d4dd977..26f70cd8 100644--- a/tests/test_hackernews.py+++ b/tests/test_hackernews.py@@ -225,13 +225,17 @@ def test_search_hackernews_depth_config(mock_request):"""Test that depth parameter controls hit count."""mock_request.return_value = {"hits": [], "nbHits": 0}- # Quick mode should request 15 hits+ # Quick mode returns up to 15 hits, but overfetches before client-side+ # engagement filtering so low-point stories do not shrink result depth.hackernews.search_hackernews("test", "2026-01-01", "2026-01-31", depth="quick")call_args = mock_request.call_args[0]url = call_args[1]- assert "hitsPerPage=15" in url+ expected_hits_per_page = (+ hackernews.DEPTH_CONFIG["quick"] * hackernews.HN_OVERFETCH_MULTIPLIER+ )+ assert f"hitsPerPage={expected_hits_per_page}" in url@patch('lib.hackernews.http.request')@@ -267,16 +271,40 @@ def test_search_hackernews_http_error_handling(mock_request):def test_search_hackernews_engagement_filter(mock_request):- """Test that low-engagement stories are filtered."""- mock_request.return_value = {"hits": [], "nbHits": 0}+ """Test that low-engagement stories are filtered client-side."""+ mock_request.return_value = {+ "hits": [+ create_mock_hit(object_id="low", points=2),+ create_mock_hit(object_id="high", points=3),+ ],+ "nbHits": 2,+ }- hackernews.search_hackernews("test", "2026-01-01", "2026-01-31")+ result = hackernews.search_hackernews("test", "2026-01-01", "2026-01-31")call_args = mock_request.call_args[0]url = call_args[1]- # Should filter for points > 2 (URL-encoded)- assert "points" in url and "%3E2" in url+ # Algolia rejects points in numericFilters; keep only supported date filters.+ assert "points" not in url+ assert [hit["objectID"] for hit in result["hits"]] == ["high"]+++@patch('lib.hackernews.http.request')+def test_search_hackernews_truncates_after_overfetch(mock_request):+ """Test that overfetching does not return more than the requested depth."""+ mock_request.return_value = {+ "hits": [+ create_mock_hit(object_id=str(i), points=10)+ for i in range(20)+ ],+ "nbHits": 20,+ }++ result = hackernews.search_hackernews("test", "2026-01-01", "2026-01-31", depth="quick")++ assert len(result["hits"]) == 15+ assert [hit["objectID"] for hit in result["hits"]] == [str(i) for i in range(15)]# === Tests for parse_hackernews_response() ===