Skip to content

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

fix(polymarket): keep domain-sweep markets the topic filter drops

Shawn Leed7709a56a055
diff --git a/skills/last30days/scripts/lib/polymarket.py b/skills/last30days/scripts/lib/polymarket.py
index f7e7b7a2..557cbb25 100644
--- a/skills/last30days/scripts/lib/polymarket.py
+++ b/skills/last30days/scripts/lib/polymarket.py
@@ -112,10 +112,7 @@ _NOISE_WORDS = frozenset({
"springs", "heights", "ridge", "bridge", "harbor", "port", "station", "center",
"square", "field", "forest", "garden", "tower", "school", "church", "camp",
"ranch", "crossing", "shore", "rock", "summit", "falls", "grove", "haven",
- # Generic tech terms that match too broadly on Polymarket
- # "cli" -> any CLI tool market; "mcp" -> protocol markets; "ai" -> every AI market
- "cli", "mcp", "protocol", "tool", "app", "code", "model", "ai", "api",
- "software", "plugin", "skill", "agent", "bot", "search", "research",
+ # Generic tech terms — see _DOMAIN_WORDS below, which is folded in here
# Generic prediction market terms
"market", "odds", "prediction", "forecast", "chance", "probability",
# Comparison-query conjunctions — should not count as informative filter tokens
@@ -123,6 +120,19 @@ _NOISE_WORDS = frozenset({
"vs", "versus",
})
+# Generic tech terms that match too broadly to be the sole signal for a NARROW
+# topic ("cli" -> any CLI tool market; "ai" -> every AI market), but which ARE
+# the subject when the topic is a domain sweep rather than one product. Kept
+# separate from the rest of _NOISE_WORDS — the directional/sports/place words
+# there exist to PREVENT false matches ("NFC West" vs a "Kanye West" search),
+# so they must never be used as a positive signal.
+_DOMAIN_WORDS = frozenset({
+ "cli", "mcp", "protocol", "tool", "app", "code", "model", "ai", "api",
+ "software", "plugin", "skill", "agent", "bot", "search", "research",
+})
+
+_NOISE_WORDS = _NOISE_WORDS | _DOMAIN_WORDS
+
def _passes_topic_filter(topic: str, event_title: str) -> bool:
"""Check if event title contains enough informative words from the topic.
@@ -166,7 +176,28 @@ def _passes_topic_filter(topic: str, event_title: str) -> bool:
# when the topic is "Mill.com food recycler" (3 informative words).
min_matches = 2 if len(informative) >= 3 else 1
- return match_count >= min_matches
+ if match_count >= min_matches:
+ return True
+
+ # Domain-word fallback. When the topic IS a domain (e.g. an AI-news sweep),
+ # the words carrying the subject — "ai", "model" — sit in _NOISE_WORDS, and
+ # the informative residue ("artificial", "intelligence") never appears in
+ # real market titles, which say "AI". That made the filter reject every AI
+ # market by construction. So if the informative words missed, fall back to
+ # the topic's own domain words. Narrow product topics ("Mill.com food
+ # recycler") contain no such words at all, so the fallback never fires for
+ # them and upstream's false-match guard is untouched.
+ domain_words = [w for w in core_words if w in _DOMAIN_WORDS]
+ if not domain_words:
+ return False
+
+ for word in domain_words:
+ if word in title_words:
+ return True
+ if len(word) >= 4 and word in title_lower:
+ return True
+
+ return False
def _passes_any_informative_word(topic: str, event_title: str) -> bool:
@@ -195,6 +226,22 @@ def _passes_any_informative_word(topic: str, event_title: str) -> bool:
return True
if len(word) >= 4 and word in title_lower:
return True
+
+ # Domain-word fallback — mirrors _passes_topic_filter. For a domain sweep
+ # ("AI frontier developments") the subject words "ai"/"model" sit in
+ # _NOISE_WORDS, so the informative residue ("frontier", "developments")
+ # never appears in real market titles and every AI market gets dropped
+ # here — undoing the parse-stage fix one stage later. Fall back to the
+ # topic's own domain words. Narrow product/comparison topics carry no
+ # _DOMAIN_WORDS, so the fallback never fires for them (behavior unchanged).
+ domain_words = [w for w in core_words if w in _DOMAIN_WORDS]
+ if not domain_words:
+ return False
+ for word in domain_words:
+ if word in title_words:
+ return True
+ if len(word) >= 4 and word in title_lower:
+ return True
return False
diff --git a/tests/test_polymarket.py b/tests/test_polymarket.py
index 4c4344fa..d22a6a9d 100644
--- a/tests/test_polymarket.py
+++ b/tests/test_polymarket.py
@@ -146,8 +146,13 @@ def test_passes_topic_filter_partial_match():
"""Test that at least one informative word must match."""
# "AI" appears in both topic and title
assert polymarket._passes_topic_filter("AI safety", "New AI Safety Conference") is True
- # "models" doesn't appear, should fail
- assert polymarket._passes_topic_filter("AI models", "New AI prediction") is False
+ # LOCAL DIVERGENCE from upstream: this asserted False, on the rule that a
+ # domain word ("ai") is too broad to be the sole match signal. That rule
+ # made domain sweeps impossible — an AI-news topic matched zero AI markets
+ # ever, because real titles say "AI" and never "artificial intelligence".
+ # _passes_topic_filter now falls back to _DOMAIN_WORDS when the informative
+ # words miss, so "AI models" does match an AI market.
+ assert polymarket._passes_topic_filter("AI models", "New AI prediction") is True
def test_passes_topic_filter_all_noise_words():