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
feat(github): unauthenticated REST fallback (U5)
Matt Van Horn6fcf1792d6bb
diff --git a/skills/last30days/scripts/lib/github.py b/skills/last30days/scripts/lib/github.pyindex ccf5b8d0..1ccb400d 100644--- a/skills/last30days/scripts/lib/github.py+++ b/skills/last30days/scripts/lib/github.py@@ -35,6 +35,10 @@ ENRICH_LIMITS = {"deep": 8,}+# Unauthenticated GitHub search allows ~10 requests/min, so cap result volume+# conservatively when running without a token to stay within the anon tier.+UNAUTH_COUNT_CAP = 10+USER_AGENT = "last30days/3.0 (research tool)"@@ -175,18 +179,12 @@ def search_github(count = DEPTH_LIMITS.get(depth, DEPTH_LIMITS["default"])core = extract_core_subject(topic)resolved_token = _resolve_token(token)- if not resolved_token:- _log("No GitHub token available (set GITHUB_TOKEN or install gh CLI)")- return {- "items": [],- "error": "no token",- "context": {- "core": core,- "from_date": from_date,- "to_date": to_date,- "count": count,- },- }+ authed = bool(resolved_token)+ if not authed:+ # Fall back to the unauthenticated REST tier instead of returning nothing.+ # It is rate-limited, so cap the request volume.+ count = min(count, UNAUTH_COUNT_CAP)+ _log("No GitHub token; using the unauthenticated REST tier (low rate limit)")_log(f"Searching for '{core}' (raw: '{topic}', since {from_date}, count={count})")# Build search query with date filter@@ -201,8 +199,16 @@ def search_github(data = _fetch_json(url, token=resolved_token, timeout=30)if not data:- return {"items": [], "context": {"core": core, "from_date": from_date,- "to_date": to_date, "count": count}}+ envelope = {"items": [], "context": {"core": core, "from_date": from_date,+ "to_date": to_date, "count": count}}+ if not authed:+ # Most likely the anon rate limit (403). Surface it so the pipeline+ # records a degraded/failed reason instead of silently showing zero.+ envelope["error"] = (+ "GitHub unauthenticated request failed (likely anon rate limit; "+ "set GITHUB_TOKEN or run gh auth login for higher limits)"+ )+ return enveloperaw_items = data.get("items", [])_log(f"Found {len(raw_items)} issues/PRs")diff --git a/skills/last30days/scripts/lib/pipeline.py b/skills/last30days/scripts/lib/pipeline.pyindex 021c9ca7..40711e01 100644--- a/skills/last30days/scripts/lib/pipeline.py+++ b/skills/last30days/scripts/lib/pipeline.py@@ -112,8 +112,9 @@ def available_sources(config: dict[str, Any], requested_sources: list[str] | Nonif which("yt-dlp") or env.is_youtube_sc_available(config):available.append("youtube")available.extend(["hackernews", "polymarket"])- if config.get("GITHUB_TOKEN") or which("gh"):- available.append("github")+ # GitHub is reachable via the unauthenticated REST tier too, so it is+ # available even without a token/gh CLI (a token only raises rate limits).+ available.append("github")if which("digg-pp-cli"):available.append("digg")if env.is_bluesky_available(config):@@ -1164,6 +1165,10 @@ def _retrieve_stream(token = github.resolve_token(config.get("GITHUB_TOKEN"))response = github.search_github(subquery.search_query, from_date, to_date, depth=depth, token=token)items = github.parse_github_response(response)+ if not items and response.get("error"):+ # Surface unauth rate-limit (or other hard failure) so the run+ # records it as degraded/failed instead of silently showing zero.+ raise RuntimeError(response["error"])items = github.enrich_with_comments(items, depth=depth, token=token)return items, {}if source == "pinterest":diff --git a/tests/test_github.py b/tests/test_github.pyindex 3e517779..c5c86dff 100644--- a/tests/test_github.py+++ b/tests/test_github.py@@ -73,16 +73,29 @@ class TestParseDate(unittest.TestCase):class TestSearchGithub(unittest.TestCase):@patch.dict("os.environ", {}, clear=True)@patch("subprocess.run", side_effect=FileNotFoundError)- def test_no_token_returns_empty_envelope(self, mock_run):+ @patch("lib.github._fetch_json", return_value=None)+ def test_no_token_unauth_rate_limited_sets_error(self, mock_fetch, mock_run):+ # No token -> unauthenticated request; on failure (likely anon rate+ # limit) the envelope carries a clear error instead of being silent.result = github.search_github("react", "2026-03-01", "2026-03-31", token=None)self.assertEqual(result.get("items", []), [])self.assertIn("error", result)- # Envelope shape must match the fetch-failure path: context is- # always present so callers (and parse_github_response) can read- # diagnostic fields without branching on which failure mode hit.+ self.assertIn("unauthenticated", result["error"].lower())self.assertIn("context", result)self.assertEqual(result["context"]["from_date"], "2026-03-01")- self.assertEqual(result["context"]["to_date"], "2026-03-31")+ # Unauth requests are capped to the low-rate tier.+ self.assertLessEqual(result["context"]["count"], github.UNAUTH_COUNT_CAP)+ # The request was actually attempted without a token (no early return).+ mock_fetch.assert_called_once()+ self.assertIsNone(mock_fetch.call_args.kwargs.get("token"))++ @patch.dict("os.environ", {}, clear=True)+ @patch("subprocess.run", side_effect=FileNotFoundError)+ @patch("lib.github._fetch_json", return_value={"items": [{"id": 1, "title": "x"}]})+ def test_no_token_unauth_success_returns_items(self, mock_fetch, mock_run):+ result = github.search_github("react", "2026-03-01", "2026-03-31", token=None)+ self.assertEqual(len(result["items"]), 1)+ self.assertNotIn("error", result)def test_resolve_token_public_alias(self):"""resolve_token is the public entry point pipeline uses; _resolve_token staysdiff --git a/tests/test_github_unauth.py b/tests/test_github_unauth.pynew file mode 100644index 00000000..c03cf58d--- /dev/null+++ b/tests/test_github_unauth.py@@ -0,0 +1,31 @@+"""Tests for unauthenticated GitHub availability + error surfacing (U5)."""++from unittest import mock++from lib import github, pipeline+++class TestUnauthAvailability:+ def test_github_available_without_token_or_gh(self):+ # GitHub is reachable via the anon REST tier, so it is available even+ # with no token and no gh CLI.+ with mock.patch.dict("os.environ", {}, clear=True):+ sources = pipeline.available_sources({})+ assert "github" in sources+++class TestUnauthCap:+ def test_unauth_caps_result_count(self):+ with mock.patch.object(github, "_resolve_token", return_value=None), \+ mock.patch.object(github, "_fetch_json", return_value={"items": []}) as fetch:+ github.search_github("kubernetes", "2026-03-01", "2026-03-31", depth="deep")+ # deep would be 60 with a token; unauth caps to UNAUTH_COUNT_CAP.+ called_url = fetch.call_args.args[0]+ assert f"per_page={github.UNAUTH_COUNT_CAP}" in called_url++ def test_authed_keeps_full_depth(self):+ with mock.patch.object(github, "_resolve_token", return_value="tok"), \+ mock.patch.object(github, "_fetch_json", return_value={"items": []}) as fetch:+ github.search_github("kubernetes", "2026-03-01", "2026-03-31", depth="deep")+ called_url = fetch.call_args.args[0]+ assert "per_page=60" in called_url