Repository navigation
refactor(commands): route slash commands through one dispatcher with a typed CommandContext - #2098
Merged
Merged
Conversation
…a typed CommandContext Move slash-command routing out of app-util.ts into source/app/utils/command-dispatcher.ts and add a StatefulCommand shape: a command that changes app state exports `run(context)`, gets a typed CommandContext from the dispatcher and returns a CommandCompletion instead of calling a completion timer itself. /clear, /rename and /status move to it as the proof, so their logic now lives in their own modules rather than in handleSpecialCommand. The remaining app-util handlers move unchanged into app/utils/handlers/ and still run before the registry until they are migrated. No behaviour change. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
No changeset foundThis PR does not add a changeset, so it will not appear in the changelog or trigger a release. If the change is user-facing, add one: pnpm changesetPick a bump (patch / minor / major) and write the changelog entry in our usual voice ("Added X... Thanks to @you. Closes #123."), then commit the generated If this PR is docs-only or a chore that needs no release note, you can ignore this — or run |
Contributor
|
nc-review could not produce a verdict this run (agent exit |
This was referenced Nov 11, 2026
jay23606
added a commit
to jay23606/nanocoder
that referenced
this pull request
Nov 12, 2026
…a typed CommandContext (Nano-Collective#2098) Move slash-command routing out of app-util.ts into source/app/utils/command-dispatcher.ts and add a StatefulCommand shape: a command that changes app state exports `run(context)`, gets a typed CommandContext from the dispatcher and returns a CommandCompletion instead of calling a completion timer itself. /clear, /rename and /status move to it as the proof, so their logic now lives in their own modules rather than in handleSpecialCommand. The remaining app-util handlers move unchanged into app/utils/handlers/ and still run before the registry until they are migrated. No behaviour change. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
3 tasks done
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.
Why
source/app/utils/app-util.tsdispatched slash commands as a chain of ~16 handlers, each re-checkingcommandParts[0], before falling back to the lazy registry. About ten commands insource/commands/are empty stubs whose real logic lives in that chain, so a stateful command touches three files, and completion is signalled withsetTimeout(onCommandComplete, 100)scattered across handlers. This is PR 1 of a sequence that moves every command onto one dispatch path.What this PR does
source/app/utils/command-dispatcher.tsexportsdispatchSlashCommand, which runs the existing resolution order unchanged: custom commands → MCP prompts → aliases (aliases.ts) → inline?key=valueoverrides → registry.app-util.tskeeps bash passthrough,handleMessageSubmissionandcreateClearMessagesHandler.StatefulCommand+CommandContext(source/types/commands.ts). A command that changes app state exportsrun(context)instead of a stubhandler. It gets a typedCommandContext(args, messages, and only the setters/services commands use so far) and returns aCommandCompletion('done'or'done-after-render'). The dispatcher is the single place that turns that intoonCommandComplete.'done-after-render'keeps the existing 100 ms delay so behaviour is unchanged; removing the delay is for a later PR.CommandRegistry.load(name)returns the real module (cached), so the dispatcher can tell a stateful command from a read-only one after theprogressLabelspinner is mounted (lazy loading and spinner timing are unchanged). The metadata proxy fromget()throws a clear error if something tries to run a stateful command throughhandler./clear,/rename,/statusnow hold their own logic insource/commands/{clear,rename,status}and are gone fromhandleSpecialCommand.handleSpecialCommand+ checkpoint load,/stats,/login) move toapp/utils/handlers/{special-command,stats,login}-handler.tsand still run before the registry until they are migrated.Behaviour
No change intended.
CommandContext.argsuses the submission'scommandArgswhen set (VS Code context stripped), the same as the old special-command path./rename,/clearand/statuscomplete on the same 100 ms delay as before. A project command namedclearstill wins over the built-in.Tests
command-dispatcher.spec.ts: context args and messages,commandArgsprecedence,'done'vs'done-after-render'timing,/clearordering (messages, then clear counter),/status, project-command precedence over a stateful built-in, spinner released when a stateful command throws, unknown commands still reach the registry's error, and the proxy refusing to run a stateful command.clear.spec.tsxused to check that the stub handler returnedundefined. It now checks the same behaviour throughrun: messages are cleared, memory proposals dropped, the app notified, and the command completes after render.app-util.spec.tstests pass unchanged (rename, status completion timing, aliases, inline overrides, retry/resume, login, stats), as dolazy-registry.spec.ts,aliases.spec.ts,help.spec.tsxandcommands.spec.ts.tsc --noEmit,biome check .,knipandknip --production --include files, plus AVA oversource/app,source/commands,source/commands.spec.ts,source/hooks,source/plainand the user-input specs. One local failure,app-container.spec"narrow boot summary places branch on its own line", depends on the branch name (it fails the same way without this change).Next
Migrate the rest in batches (mode-entering commands: model/settings/explorer/ide/tune; then checkpoint load, resume, retry; stats/login with a deferred completion; compact/context-max/create handlers), delete
create-stub-command.tsand the handler chain, and replace the remainingsetTimeoutcompletions.🤖 Generated with Claude Code