cli-microsoft365: Suggest correct command when incorrect command name provided
When the user provides an incorrect command name, let’s use our Mendable integration to try to deduct the correct equivalent.
When the user provided an incorrect command name, and the CLI is configured in interactive mode:
- we take the invalid command name without options
- we embed it in a prompt
- we start a new conversation with Mendable and send the prompt with the invalid message
- if we get a response with the correct command name, we show the user the message:
Did you mean: m365 correct command --all their --options
- if we get a response
command_not_found
, we show the user a humand-readable message like: `Unfortunately, we couldn’t find a matching command. Run ‘m365 help’ to see the list of available commands, or use the 🌶️ assistant to enter what you’d like to accomplish, eg. ‘m365? “How to upgrade an SPFx project?”’
Here’s the prompt that we could use which seem to work:
A user incorrectly typed command name: "<command name here>". Which command did they mean? If you find a matching command, return only the correct command's name in plain-text. Do not reply in full sentence, but instead return just the command's name. Ensure that the command's name starts with 'm365'. If you don't find a matching command, return "command_not_found".
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 1
- Comments: 26 (25 by maintainers)
Perfect, I’ll open up the issue. Quite busy to pick it up myself but I’ll keep tabs.
In the past, I’ve played around a bit with the fuzzy search. So I’ll see if I can craft up a POC for it 😄
in case you’re open to using something much faster and smaller than Fuse.js, i’ve done an pretty thorough comparison of a few dozen fuzzy libs here: https://github.com/leeoniya/uFuzzy#a-biased-appraisal-of-similar-work
here’s a demo comparing just a few libs, including Fuse.js with a 4MB corpus: https://leeoniya.github.io/uFuzzy/demos/compare.html?libs=uFuzzy,fuzzysort,QuickScore,Fuse&search=super ma
you can drag/drop your own list into that UI, too 😃
@pnp/cli-for-microsoft-365-maintainers, any further thoughts regarding the POC that was created using the
Fuse.js
library?I think this library could be quite helpful to get this enhancement implemented.
Amazing suggestion! I think something similar would also be awesome if it could validate the option names but that’s more complex. One point we should consider is that AI responses are good at giving totally incorrect/made-up suggestions. Would there be a way for us to prevent stuff like this from happening?
Another idea could maybe be to implement this logic using e.g. Fuse.js. This is a lightweight library that is all about typos 😄 Here we could also provide a whole bunch of options that could help us fine-tune the results.
Difficult roads often lead to beautiful destinations 😊 It’s not that difficult, just don’t reinvent the wheel.
I would love to give this a go, however it’ll be quite a hard one I think 😁
BTW, just a stupid idea, but maybe first time we detect someone did a spelling mistake we could suggest setting up command completion https://pnp.github.io/cli-microsoft365/user-guide/completion
I guess in many cases it helps to type/tab the command, option correctly 😅
It all depends on how well fuzzy search can match our command names. We should definitely give it a try as it’s a solid option for what we’re trying to accomplish. If it’s good enough, then I agree that it would be preferable over AI.
Would anyone like to do a PoC with a couple of command names to see how well fuzzy search would work?
Let’s do it!
That’s a great point! Most mistakes are probably because users aren’t using abbreviations. At first, I thought making this work with
Fuse.js
would be a real challenge, but I managed to get it somewhat working 😄I’ve updated the POC to also function without abbreviations and provide suggestions for the right command. Just a heads up, I’ve only applied this to commands from
m365 docs
tom365 aad uservoiceidentityreport set
. So, I’d recommend giving it a try with “azure active directory”I like it @Jwaegebaert, seems to work nicely!
I don’t think that would be impossible.
Nice PoC @Jwaegebaert! Love it!