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(x): FROM + ABOUT lanes, both weighted (fix from:-AND-bug, add mentions) (#610)

Matt Van Horna1bda566502f
diff --git a/skills/last30days/scripts/lib/bird_x.py b/skills/last30days/scripts/lib/bird_x.py
index b7ea5d34..41d61ddf 100644
--- a/skills/last30days/scripts/lib/bird_x.py
+++ b/skills/last30days/scripts/lib/bird_x.py
@@ -394,12 +394,15 @@ def search_handles(
) -> List[Dict[str, Any]]:
"""Search specific X handles for topic-related content.
- Runs targeted Bird searches using `from:handle topic` syntax.
- Used in Phase 2 supplemental search after entity extraction.
+ Pulls each handle's actual timeline via `from:handle since:` — the FROM
+ lane (tweets BY the person), engagement-weighted downstream. The topic is
+ used for relevance RANKING, never AND'd into the query: X search is literal,
+ so `from:handle <their name>` only matched tweets where they wrote their own
+ name and returned ~0. Used in Phase 2 after entity extraction.
Args:
handles: List of X handles to search (without @)
- topic: Search topic (core subject), or None for unfiltered search
+ topic: Search topic — used for relevance ranking only, not the query
from_date: Start date (YYYY-MM-DD)
count_per: Results to request per handle
@@ -410,10 +413,8 @@ def search_handles(
def _search_one_handle(handle: str) -> List[Dict[str, Any]]:
handle = handle.lstrip("@")
- if core_topic:
- query = f"from:{handle} {core_topic} since:{from_date}"
- else:
- query = f"from:{handle} since:{from_date}"
+ # Always unfiltered: pull the timeline, rank by topic relevance below.
+ query = f"from:{handle} since:{from_date}"
cmd = [
"node", str(_BIRD_SEARCH_MJS),
@@ -461,6 +462,77 @@ def search_handles(
return all_items
+def search_mentions(
+ handles: List[str],
+ from_date: str,
+ count_per: int = 5,
+) -> List[Dict[str, Any]]:
+ """Search for tweets ABOUT/TO each handle — the mention lane.
+
+ Queries `@handle since:` (tweets that mention the account) and excludes the
+ handle's OWN tweets (those belong to the FROM lane via search_handles), so
+ this surfaces what OTHERS are saying about the person. Engagement-weighted
+ downstream; deduped against the FROM lane by URL at normalize time.
+
+ Args:
+ handles: List of X handles (without @)
+ from_date: Start date (YYYY-MM-DD)
+ count_per: Results to request per handle
+
+ Returns:
+ List of raw item dicts (same format as parse_bird_response output).
+ """
+ def _search_one(handle: str) -> List[Dict[str, Any]]:
+ handle = handle.lstrip("@")
+ query = f"@{handle} since:{from_date}"
+ cmd = [
+ "node", str(_BIRD_SEARCH_MJS),
+ query,
+ "--count", str(count_per),
+ "--json",
+ ]
+ try:
+ result = subproc.run_with_timeout(cmd, timeout=15, env=_subprocess_env())
+ except subproc.SubprocTimeout:
+ _log(f"Mention search timed out for @{handle}")
+ return []
+ except OSError as e:
+ _log(f"Mention search error for @{handle}: {e}")
+ return []
+ if result.returncode != 0:
+ _log(f"Mention search failed for @{handle}: {result.stderr.strip()}")
+ return []
+ output = result.stdout.strip()
+ if not output:
+ return []
+ try:
+ response = json.loads(output)
+ except json.JSONDecodeError:
+ _log(f"Invalid JSON from mention search for @{handle}")
+ return []
+ items = parse_bird_response(response, query=None)
+ # ABOUT lane = OTHERS mentioning the handle. Drop the handle's own tweets
+ # (the FROM lane already covers those); identify by the status URL author.
+ hl = handle.lower()
+ # The Bird API may return either x.com or twitter.com permalinks, so
+ # match both when excluding the handle's own tweets.
+ def _is_own(url):
+ u = (url or "").lower()
+ return f"x.com/{hl}/status" in u or f"twitter.com/{hl}/status" in u
+ about = [it for it in items if not _is_own(it.get("url"))]
+ _log(f"Searching: {query} -> {len(about)} mentions")
+ return about
+
+ from concurrent.futures import ThreadPoolExecutor, as_completed
+
+ all_items: List[Dict[str, Any]] = []
+ with ThreadPoolExecutor(max_workers=min(5, len(handles))) as executor:
+ futures = {executor.submit(_search_one, h): h for h in handles}
+ for future in as_completed(futures):
+ all_items.extend(future.result())
+ return all_items
+
+
def parse_bird_response(response: Dict[str, Any], query: str = "") -> List[Dict[str, Any]]:
"""Parse Bird response to match xai_x output format.
diff --git a/skills/last30days/scripts/lib/pipeline.py b/skills/last30days/scripts/lib/pipeline.py
index f7c02773..c8ae6335 100644
--- a/skills/last30days/scripts/lib/pipeline.py
+++ b/skills/last30days/scripts/lib/pipeline.py
@@ -855,17 +855,25 @@ def _run_supplemental_searches(
ranking_query = plan.subqueries[0].ranking_query if plan.subqueries else topic
primary_label = plan.subqueries[0].label if plan.subqueries else "primary"
- # Search primary handles (full weight)
+ # Search primary handles (full weight): FROM lane (their own tweets) +
+ # ABOUT lane (tweets mentioning them). Both engagement-weighted and deduped
+ # by URL at normalize time.
if handles:
+ # Independent try/except per lane so a failure in one does not discard
+ # the other's already-computed results.
+ from_items: list = []
+ about_items: list = []
try:
- raw_items = bird_x.search_handles(
- handles, topic, from_date, count_per=3,
- )
+ from_items = bird_x.search_handles(handles, topic, from_date, count_per=3)
except Exception as exc:
- print(f"[Pipeline] Phase 2 handle search failed: {exc}", file=sys.stderr)
+ print(f"[Pipeline] Phase 2 FROM-lane search failed: {exc}", file=sys.stderr)
if not bundle.items_by_source.get("x"):
- bundle.errors_by_source["x"] = f"Phase 2 handle search: {exc}"
- raw_items = []
+ bundle.errors_by_source["x"] = f"Phase 2 FROM-lane: {exc}"
+ try:
+ about_items = bird_x.search_mentions(handles, from_date, count_per=3)
+ except Exception as exc:
+ print(f"[Pipeline] Phase 2 ABOUT-lane search failed: {exc}", file=sys.stderr)
+ raw_items = from_items + about_items
if raw_items:
normalized = _normalize_score_dedupe(
diff --git a/tests/test_bird_x.py b/tests/test_bird_x.py
index bf64a276..412b3c31 100644
--- a/tests/test_bird_x.py
+++ b/tests/test_bird_x.py
@@ -304,6 +304,71 @@ if __name__ == "__main__":
unittest.main()
+class TestXFromAndAboutLanes(unittest.TestCase):
+ """U7/U8: FROM lane drops the topic-AND; ABOUT lane queries @handle and
+ excludes the handle's own tweets."""
+
+ def _result(self, body_items):
+ import json as _j
+ class _R:
+ returncode = 0
+ stderr = ""
+ r = _R()
+ r.stdout = _j.dumps({"items": body_items})
+ return r
+
+ def test_from_lane_drops_topic_and(self):
+ from unittest import mock
+ from lib import bird_x
+ captured = []
+
+ def fake_run(cmd, timeout=None, env=None):
+ captured.append(cmd[2]) # the query string arg
+ return self._result([])
+
+ with mock.patch.object(bird_x.subproc, "run_with_timeout", side_effect=fake_run):
+ bird_x.search_handles(["xuezhao"], "lan xuezhao", "2026-05-19", count_per=1)
+ self.assertEqual(captured[0], "from:xuezhao since:2026-05-19")
+ self.assertNotIn("lan xuezhao", captured[0])
+
+ def test_mention_lane_queries_at_handle(self):
+ from unittest import mock
+ from lib import bird_x
+ captured = []
+
+ def fake_run(cmd, timeout=None, env=None):
+ captured.append(cmd[2])
+ return self._result([])
+
+ with mock.patch.object(bird_x.subproc, "run_with_timeout", side_effect=fake_run):
+ bird_x.search_mentions(["xuezhao"], "2026-05-19", count_per=1)
+ self.assertEqual(captured[0], "@xuezhao since:2026-05-19")
+
+ def test_mention_lane_excludes_own_tweets(self):
+ from unittest import mock
+ from lib import bird_x
+ parsed = [
+ {"url": "https://x.com/xuezhao/status/1", "title": "own tweet"},
+ {"url": "https://twitter.com/xuezhao/status/3", "title": "own legacy-domain tweet"},
+ {"url": "https://x.com/fan99/status/2", "title": "mention of them"},
+ ]
+ with mock.patch.object(bird_x.subproc, "run_with_timeout",
+ return_value=self._result([{"id": "x"}])), \
+ mock.patch.object(bird_x, "parse_bird_response", return_value=parsed):
+ out = bird_x.search_mentions(["xuezhao"], "2026-05-19", count_per=5)
+ urls = [it["url"] for it in out]
+ self.assertNotIn("https://x.com/xuezhao/status/1", urls) # own (x.com) excluded
+ self.assertNotIn("https://twitter.com/xuezhao/status/3", urls) # own (twitter.com) excluded
+ self.assertIn("https://x.com/fan99/status/2", urls) # mention kept
+
+ def test_mention_lane_empty_when_no_mentions(self):
+ from unittest import mock
+ from lib import bird_x
+ with mock.patch.object(bird_x.subproc, "run_with_timeout",
+ return_value=self._result([])), \
+ mock.patch.object(bird_x, "parse_bird_response", return_value=[]):
+ out = bird_x.search_mentions(["xuezhao"], "2026-05-19")
+ self.assertEqual(out, [])
class TestProbeAndDiagnoseHonesty(unittest.TestCase):
"""U5: --diagnose probe + true auth lane; X is not reported green when dead."""