First, you should leave that jurisdiction ASAP.
Was your taillight really out? Did they cite you or give you a written warning about that? Not that it really matters… the cops always got “not tracking a lane” as an all-purpose excuse to pull anyone over.
Once they pull you over, they can always do what’s called a “Terry Stop”. That’s what the Qs about weapons are about (also quite often Qs about needles too). It doesn’t matter what you answer… they can always ask anyone in the car to get out of the car, and pat them down.
Cops can always ask to search your car or body. They don’t need a reason. They can run dogs on you too if they have them there, just as a goof. As for calling the dogs in and having you wait, as a practical matter they can do that too. They proly want to CYA the dog call in however… that’s where the comment about “being nervous” comes into play. Of course most peeps are going to be nervous when detained by armed goons… so that works as another all-purpose excuse like tracking lanes.
Cops can always lie and in general make vague threats like you related.
Bottom line: since “nothing happened” (except you being interrogated and threatened by armed goons, and having your time wasted)… there is no legal remedy. That… and I’m not a lawyer, so lol @ listening to me regarding legal matters.
What you could do is (once you are safely far enough away) is file a complaint with whoever accepts complaints regarding this gang of cops. It could help (yea right, in theory, but maybe) establish a pattern of inappropriate stops by these cops or this department. Also… even if you did want to get a lawyer involved, you’d certainly want to exercise any administrative options you have first, before taking any legal action.
ETA: Corrected name and added link for “Terry Stop” above.