Skip to content

Refactor command routing for a plugin-friendly structure - #2388

Merged
Re-bin merged 1 commit into
mainfrom
feat/command-router
Mar 23, 2026
Merged

Re-bin merged 1 commit into
mainfrom
feat/command-router

Conversation

@Re-bin

@Re-bin Re-bin commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR pulls slash command handling out of AgentLoop and moves it into a dedicated nanobot.command package.

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

  • added a dedicated nanobot.command package
  • moved command routing into nanobot.command.router
  • moved built-in slash commands into standalone handlers in nanobot.command.builtin
  • replaced in-loop _cmd_* implementations with register_builtin_commands(...)
  • passed command execution through CommandContext, including access to loop state where needed
  • removed the old nanobot.utils.router module
  • kept nanobot.cli.commands as the CLI entrypoint to avoid breaking installed console scripts
  • renamed nanobot.cli.onboard_wizard to nanobot.cli.onboard
  • renamed nanobot.cli.model_info to nanobot.cli.models
  • updated tests to follow the new command module layout
  • excluded nanobot/command/ from core_agent_lines.sh core-agent line counting

Why

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:

  • AgentLoop remains responsible for message orchestration
  • CommandRouter becomes the dispatch mechanism
  • built-in commands live in a predictable place
  • future command extension has a cleaner foundation

This does not fully solve pluginization by itself, but it creates a better boundary for that next step.

Design notes

  • priority commands such as /stop, /restart, and /status are still intercepted before normal dispatch
  • exact-match commands such as /new and /help continue to run through the regular command router path
  • built-in handlers are now standalone async functions rather than methods on AgentLoop
  • handlers currently receive ctx.loop so they can still access existing runtime services without duplicating wiring

Compatibility

One important detail is that the CLI entrypoint remains:

nanobot.cli.commands:app

I 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

  • Run full test suite
  • Verify built-in slash commands still resolve through the new router structure
  • Verify priority command handling still bypasses the normal dispatch path where intended
  • Verify CLI imports still work with nanobot.cli.commands preserved as the script entrypoint
  • Verify onboarding imports still work after renaming helper modules

Result

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.

@Re-bin
Re-bin merged commit 20494a2 into main Mar 23, 2026
3 checks passed
@Re-bin
Re-bin deleted the feat/command-router branch March 23, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant