Repository navigation
Refactor command routing for a plugin-friendly structure - #2388
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR pulls slash command handling out of
AgentLoopand moves it into a dedicatednanobot.commandpackage.The goal is to keep the agent loop focused on orchestration, while making command handling easier to extend, reason about, and eventually open up for more pluggable command registration.
What changed
nanobot.commandpackagenanobot.command.routernanobot.command.builtin_cmd_*implementations withregister_builtin_commands(...)CommandContext, including access to loop state where needednanobot.utils.routermodulenanobot.cli.commandsas the CLI entrypoint to avoid breaking installed console scriptsnanobot.cli.onboard_wizardtonanobot.cli.onboardnanobot.cli.model_infotonanobot.cli.modelsnanobot/command/fromcore_agent_lines.shcore-agent line countingWhy
Before this change, slash command handling lived directly inside
AgentLoop, which made the loop file continue to grow as more top-level commands were added.By moving routing and handlers into a dedicated package, the structure becomes clearer:
AgentLoopremains responsible for message orchestrationCommandRouterbecomes the dispatch mechanismThis does not fully solve pluginization by itself, but it creates a better boundary for that next step.
Design notes
/stop,/restart, and/statusare still intercepted before normal dispatch/newand/helpcontinue to run through the regular command router pathAgentLoopctx.loopso they can still access existing runtime services without duplicating wiringCompatibility
One important detail is that the CLI entrypoint remains:
nanobot.cli.commands:appI originally renamed that module as part of the cleanup, but restored it after realizing this would break existing installed console scripts unless users reinstalled the package. Keeping the entrypoint stable avoids that migration hazard for now.
Test plan
nanobot.cli.commandspreserved as the script entrypointResult
This refactor reduces command-specific weight inside
AgentLoop, gives command handling a clearer home, and sets up a more maintainable structure for future command growth.