I think that if a country harbors terrorists, the US should depose the government, and withdraw. The US should threated to come back and do it again, repeating as necessary, until the government stops harboring terrorists.
In fact, that it the only way to stop terrorism. And it would be incredibly effective, since the US would only have to do it once or twice in the whole world (or maybe even 0 times), to prove that they will do it.
I don't believe in the use of initiated force. But a government that harbors terrorists is initiating force against the US, and it's morally proper for the US to use retaliatory force to resolve the problem.
Force will be met with force. Don't use force, and you won't be subject to it.
In the 1 case in the world of a failed state---Somalia---I think a reasonable strategy would be to pick a winner and provide them with funding and weapons to establish a government over the territory.
You seem to be under some sort of delusion that most terrorist groups would see the toppling of the government of the country they are operating out of as a bad thing.
If that someone is more terrorists, rinse and repeat.
There is not an infinite supply of terrorists. And if more terrorists fill the power vacuum, you're likely to eventually get a groups that decides they'd rather keep being in power than be aggressively wiped out.
Moreover, this greatly incentivizes all non-terrorists to cooperate and work together to form a government that will not be subject to US attack and will not cause their country to stay in a permanent state of war.
I think these incentives are so strong, that only 1 country would ever need to be made an example of.
If it weren't for Obama destroying American credibility to act on its threats, it would likely take 0 actual examples. But since nobody believes America will enact its own foreign policy anymore, it would now probably take 1 example.
There are only two ways to deal with force: cower in fear forever, which is what the US is doing now, to the massive detriment of its citizens' safety (mainly due to overgrowth of government such as the NSA), or just eliminate the threat.
And there is nothing morally wrong with responding with force to someone who threatens you with force.
Foruntately, the US military is so overwhelmingly dominant that pretty much any "terrorist threat" is like a fly to a giant. Even eliminating Saddam, a professional warload with a whole country at his disposal, was a sure thing---it was just a question of how few lives the US could lose.
Unfortunately, the US leadership will not adopt this doctrine in the short term, and probably never. The current Republicans and Democrats are totally opposed to using the kind of rational, moral clarity that is necessary. They would prefer to waffle and "negotiate." It would take a sea-change in the structure of the Republican party for America to ever adopt this doctrine, and is even less likely for the Democrats.