In UseItemCommand.java (and all the other CLI commands that have item names as parameters), ItemFinder.getMatchingItemList() is used to parse the item list. This in turns uses ItemFinder.getFirstMatchingItem() on each substring in the list of parameters you entered in the gCLI.
ItemFinder.getFirstMatchingItem() gets a list of item names that contain the substring with ItemFinder.getMatchingNames( String searchString ) and then calls ItemFinder.getFirstMatchingItemName( List nameList, String searchString, int filterType ).
What I don't understand is that ItemFinder.getFirstMatchingItemName() doesn't use searchString at all, it just removes entries from nameList if there are multiple matches such that one is a substring of the others. I guess the actual disambiguation happens in ItemFinder.getMatchingNames), but I don't really understand where.
From glancing at the revision log, I think that fuzzy matching in CLI commands is an intended KoLMafia feature - the fact that 'milk' will match a specific item instead of leading to an error asking the user to disambiguate is done on purpose. Changing this would probably require quite an overhaul.
ETA: the cases where Mafia asks for disambiguation (Candy hearts, snowcones and cupcakes apparently) are hardcoded in ItemFinder.getFirstMatchingItemName().
EDIT2: I forgot to look at ItemFinder.filterNameList() - it looks like Bale nailed it: restorers take precedence for disambiguation.
EDIT3: there still are strange things happening though:
Code:
> use glass
Searching for "clan looking glass"...
Stopped purchasing Clan looking glass @ 20,750,000.
Using cached search results for Clan looking glass...
Stopped purchasing Clan looking glass @ 20,750,000.
You need 1 more Clan looking glass to continue.