I've watched President Barack Obama's foreign policy for five years now. And I've finally figured what it's all about, thanks largely to Bob Woodward and "Star Trek."

This is really not as strange a combination as it appears. Woodward's early reveal of Robert Gates' view, expressed in his new memoir "Duty," that President Obama never really believed in the Afghanistan war or the surge is hardly a shocker. But it confirms something I've sensed for some time now.

Obama was only 5 when the hit series "Star Trek" made its debut in 1966. But I'd wager that the president must have loved the show and watched the reruns, because he modeled his key foreign policy doctrine after one of the most important themes of the series: the Prime Directive.

Now, the Prime Directive is a very complex principle. After all, this is a television show for most of us — but a way of life complete with its own terminology and philosophy for its devotees. But essentially it boils down to this: Interference in the affairs of the internal development of an alien planet is strictly prohibited, whether or not the planet's inhabitants have knowledge of warp-speed travel or not.

The basic reasoning behind the Prime Directive, summed up by one of my favorite "Star Trek" spin-off captains, Jean-Luc Picard, is that "history has proven again and again that whenever mankind interferes with a less developed civilization, no matter how well intentioned that interference may be, the results are invariably disastrous."

There is only one exception that permits interference: when the mysterious and galactically catastrophic Omega molecules are detected. These particles are hugely unstable, and the careless and unplanned destruction of a single molecule can nullify subspace for many light-years around it, rendering faster-than-the-speed-of-light travel impossible.

If that happens, well ... there goes the show! So the Prime Directive is superseded only by General Order 0 — the Omega Directive — which permits Starfleet commanders to intervene when Omega particles are detected.

Don't get me wrong. Barack Obama isn't Commander James T. Kirk. Nor is space — the final frontier — the foreign policy world in which the president operates.

The most important difference between Star Trek and our current reality is that the emotional and volatile Kirk — usually driven by some higher good or other moral purpose — violates the Prime Directive when he sees fit, but President Obama — much cooler and more temperamentally aligned with the Vulcan Spock — never does.

Indeed, with the exception of the Libya intervention and his policy on drones (that's not really intervention in the affairs of an entire civilization ... right?), Barack Obama has scrupulously adhered to his version of Prime Directive. What would cause him to violate it — what his own Omega Directive would be — is not at all clear.

From the beginning of his administration, it was clear that Obama's principle of non-interference — certainly on the military side — in foreign and distant lands would represent the most important tenet of his foreign policy. It was exemplified, certainly, in the expressed mantra of getting America "out of profitless wars, not into new ones." He had already voted against the Iraq war as a senator, and while he identified Afghanistan as the good war, his heart — as Gates makes clear — was never in that one either. The Afghan surge was at its core the opening shot in a campaign of U.S. extrication; to anyone who was reading the administration's intentions, getting in deeper in fact was designed to facilitate an eventual run for the exits. This may be patently absurd in terms of logic, but it's true.

Even in Libya, things weren't what they seemed. Anyone who thought that the multilateral intervention there reflected the beginning of a Bush 43-like trend to nation-build or a muscular policy of supporting fledgling democrats against aging dictators was destined for disappointment. After all, the administration had helped show Hosni Mubarak the door in Egypt and made clear America had to be on the right side of history, but it then had neither the will nor skill to craft a robust and consistent strategy of engagement in response to fast-breaking events sweeping an entire region. (In fairness to the administration, given the complexity of the Arab Spring, what kind of comprehensive strategy was really possible anyway? To this day, none of the so-called foreign policy experts out there has offered a strategy that could have done any better — that is done anything more than affect matters at the margins.)

If his risk-aversion wasn't altogether clear in the president's first term, it has become stunningly clear in his approach to Syria and Iran during the second. Whatever Kirk-like risk readiness there was among his leadership team for military intervention in places like Syria or even for cutting off all assistance to anti-democratic Egyptian generals, it stopped Spock-like at the water's edge.

The comparisons don't end with the Prime Directive, however. The other half of the Obama administration's foreign policy philosophy is the fundamental belief in diplomacy as the talking cure — and this, too, is Star Trek-like in character.

To be sure, the universe is a dangerous place, and the Enterprise often finds itself in mortal peril, resorting to force in many of its adventures. But peaceful transaction, negotiation, rational discourse, and enlightened self-interest are in fact just as much the Star Trek way.

Not an episode of the old series went by without an alien ambassador or delegation from some planet presenting some new idea for interplanetary cooperation. After all, this is the 23rd century, and although there had apparently been a World War III, the earth had survived. So Kirk's planet must finally have learned a thing or two about how to live together peacefully.

Obama's commitment to talking, not shooting, was also evident from the beginning of his administration. A young, internationalist-minded president with transformative pretentions both at home and abroad believed he could change his world. His supporters and much of the international community encouraged this thinking, too. (Look no further than Obama's 2010 Nobel Peace Prize for proof of this.)

Predictably, during his first term, aspirations surpassed capacity, expectations trumped delivery, and rhetoric exceeded results. By the end of 2010, neither engaging Iran, resetting relations with Russia, nor moving the Israeli-Palestinian peace process forward had succeeded. And it appeared that the "yes we can" president had become a "maybe we can't" leader.

Since then, much of Obama's transformative pretentions have given way to more grounded realities. But the faith in engaging diplomatically rather than dropping bombs hasn't weakened. The Starship Diplomacy has plenty of warp drive, and its captain, Secretary of State John Kerry, plans to cover millions of parsecs in the next several years.

For Obama, this journey is clearly designed to protect his Prime Directive and thus avoid war and messy military interventions. Just think about the journeys of the Diplomacy so far.

In Syria, the goal of negotiations was to avoid an open-ended military intervention. Even the president's professed red line for war — the Syrian regime's use of chemical weapons against civilians — became a catalyst for deal-making and a trade: If the chemical weapons go, President Bashar Assad stays. (I have no empirical evidence to prove it, but I'm also convinced that the president's desire to avoid military action in Syria was driven by his conviction that striking there would have triggered a proxy war with Iran and would have made a deal on the nuclear issue much harder.)

The same logic of using diplomacy to preempt war applies to negotiations over Iran's nuclear weapons program. The president's Iran policy aims to achieve three things: avoid an Israeli strike against Iran; preempt the need for an American one; and delay Iran's becoming a nuclear weapons threshold state on Obama's watch. Let Chris Christie or Hillary Clinton deal with it. And in Obama's view, the only way to do these things, and thus protect the Prime Directive, is to use diplomacy to render unnecessary the need or desire for military action.

I don't mean to suggest that Obama is a pacifist. He's been a wartime president and a tough trader in counterterrorism since his first day in office. And unlike the United Federation of Planets, the point of his Prime Directive isn't purely moral or philosophical. Rather, for Obama, the Prime Directive is driven by a practical belief that the use of military power in open-ended situations to achieve political objectives abroad is risky, costly, unpopular, and likely to undermine what he really cares about: his domestic agenda. After all, the success of his presidency will be shaped more by whether he can regain the momentum on his now troubled health-care initiative, the economy, and other social issues like immigration than by looking for Klingons to fight. What's more, Obama is correctly reading the public, who also have a stake in wanting strict adherence to the Prime Directive. Coming off the two longest wars in American history and the most severe economic downturn since the Great Depression, Obama presides over a people fed up with foreign adventures and wanting to be healed at home.

Under what circumstances would the president violate the Prime Directive, abandon the Starship Diplomacy, and consider serious and sustained military intervention in a foreign land? In the wake of Afghanistan and Iraq, and based on everything he's said and done to date, I can see only one situation: another catastrophic terrorist attack on the homeland.

Whether you agree with Obama or not, his "Star Trek" approach to foreign policy is actually quite logical, a Vulcan might say. The ultimate goal, after all, is to live long and prosper — as a nation, as a people.

• -

Aaron David Miller, FP columnist, is vice president for new initiatives and a scholar at the Woodrow Wilson International Center for Scholars. His forthcoming book is titled "Can America Have Another Great President?"