From dd79e07fb302b69ecd4a0e04f58efb68cd900f75 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Tue, 5 May 2026 13:42:22 +0200 Subject: [PATCH] fix(behaviors): prevent rabbit hole from activating on non-feed screens and add tap post username context gate --- GramAddict/core/behaviors/rabbit_hole.py | 10 ++++++++++ GramAddict/core/perception/context_gate.py | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/GramAddict/core/behaviors/rabbit_hole.py b/GramAddict/core/behaviors/rabbit_hole.py index 1d6a5a6..09bddf8 100644 --- a/GramAddict/core/behaviors/rabbit_hole.py +++ b/GramAddict/core/behaviors/rabbit_hole.py @@ -34,6 +34,16 @@ class RabbitHolePlugin(BehaviorPlugin): if res_score < 0.8: return False + screen_type = ctx.shared_state.get("current_screen_type") + if not screen_type and ctx.context_xml: + from GramAddict.core.perception.screen_identity import ScreenIdentity + screen_type = ScreenIdentity(getattr(ctx, "username", "")).identify(ctx.context_xml).get("screen_type") + + from GramAddict.core.perception.screen_identity import ScreenType + valid_screens = [ScreenType.HOME_FEED, ScreenType.EXPLORE_GRID, ScreenType.REELS_FEED] + if screen_type not in valid_screens: + return False + config = self.get_config(ctx) percentage = float(config.get("percentage", 15)) return random.random() < (percentage / 100.0) diff --git a/GramAddict/core/perception/context_gate.py b/GramAddict/core/perception/context_gate.py index 710285d..1efd4fa 100644 --- a/GramAddict/core/perception/context_gate.py +++ b/GramAddict/core/perception/context_gate.py @@ -67,6 +67,14 @@ ALLOWED_SCREENS: Dict[str, FrozenSet[ScreenType]] = { ScreenType.STORY_VIEW, # toolbar_reshare_button exists on stories } ), + "tap post username": frozenset( + { + ScreenType.HOME_FEED, + ScreenType.POST_DETAIL, + ScreenType.REELS_FEED, + ScreenType.EXPLORE_GRID, + } + ), } # Intent keywords that trigger the categorical ban check