feat: passthrough unknown slash commands to Claude in agentic mode#131
feat: passthrough unknown slash commands to Claude in agentic mode#131haripatel07 wants to merge 5 commits intoRichardAtCT:mainfrom
Conversation
In agentic mode, unknown slash commands (e.g. /workflow, /skill, /add-memory) were silently dropped because the TEXT handler excluded all COMMAND messages. Remove ~filters.COMMAND from the agentic text handler so unrecognised slash commands are forwarded to Claude as natural language. Registered commands (/start, /new, /status, etc.) still take priority via higher-priority CommandHandlers and are unaffected. Classic (non-agentic) mode retains the original filter — unknown commands are not forwarded there. Closes RichardAtCT#129
There was a problem hiding this comment.
Pull request overview
This PR removes the ~filters.COMMAND exclusion from the agentic mode text MessageHandler filter, intending to allow unknown slash commands (e.g., /workflow, /skill) to pass through to Claude as natural language text.
Changes:
- Removed
~filters.COMMANDfrom thefilters.TEXTfilter in the agenticMessageHandlerregistration in_register_agentic_handlers.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/bot/orchestrator.py
Outdated
| app.add_handler( | ||
| MessageHandler( | ||
| filters.TEXT & ~filters.COMMAND, | ||
| filters.TEXT, |
There was a problem hiding this comment.
Bug: Removing ~filters.COMMAND will cause registered slash commands (e.g. /start, /new, /status, /verbose, /repo, /restart) to be processed twice — once by the CommandHandler in the default group (0) and again by agentic_text in group 10.
In python-telegram-bot, handler groups are independent: a match in group 0 does not prevent handlers in group 10 from also firing. Only ApplicationHandlerStop can stop cross-group propagation, and it is not raised anywhere in this codebase.
This means typing /start will both run agentic_start and send "/start" to Claude as a text message.
To fix this while still passing through unknown slash commands, you should keep ~filters.COMMAND but add a fallback MessageHandler with filters.COMMAND in the same group (10) that only fires for unrecognised commands. Alternatively, you could move the CommandHandlers into group 10 as well (so they share the same group as the text handler and block it), or raise ApplicationHandlerStop in each command handler to prevent further group processing.
|
PR Review Summary
What looks good
Issues / questions
Suggested tests
Verdict — Friday, AI assistant to @RichardAtCT |
Previous approach (removing ~filters.COMMAND) caused registered commands like /start and /new to fire twice — once via CommandHandler (group 0) and again via the agentic text handler (group 10). Fix: revert TEXT filter and add a separate filters.COMMAND MessageHandler in group 10 that dispatches to _handle_unknown_command(). That method checks the command name against KNOWN_COMMANDS and returns early for registered ones, forwarding only truly unknown slash commands to Claude. Dispatch flow: - /start, /new, /status ... -> CommandHandler (group 0) only - /workflow, /skill, /add-memory ... -> forwarded to Claude via agentic_text - Regular text -> TEXT & ~filters.COMMAND handler as before Also updates test to expect 5 message handlers (was 4).
|
PR Review Summary
What looks good
Issues / questions
Suggested tests (if needed)
Verdict — Friday, AI assistant to @RichardAtCT |
…ation, routing tests - Add ClassVar[frozenset[str]] type annotation on _known_commands (mypy strict) - Derive _known_commands dynamically from registered handlers list to prevent drift when new commands are added in future - Remove hardcoded KNOWN_COMMANDS class variable - Add 3 routing tests: - test_known_command_not_forwarded_to_claude - test_unknown_command_forwarded_to_claude - test_bot_suffixed_command_not_forwarded
|
PR Review (Incremental review from Summary
What looks good
Issues / questions
Verdict — Friday, AI assistant to @RichardAtCT |
|
PR Review (Incremental review from Summary
What looks good
Issues / questions
Verdict — Friday, AI assistant to @RichardAtCT |
Problem
In agentic mode, unknown slash commands (e.g.
/workflow,/skill,/add-memory)were silently dropped because the
TEXThandler excluded allCOMMANDmessages viafilters.TEXT & ~filters.COMMAND.Fix
Remove
~filters.COMMANDfrom the agentic textMessageHandlerso unrecognisedslash commands are forwarded to Claude as natural language.
Registered commands (
/start,/new,/status, etc.) still take priority viahigher-priority
CommandHandlers and are completely unaffected.Classic (non-agentic) mode retains the original filter — unknown commands are
not forwarded there.
Change
src/bot/orchestrator.pyline ~321:Related Issue
Closes #129
Type of Change
Testing