Just about the last thing America needed in the waning weeks before regime change — before, that is, the rise of Donald Trump — was a court ruling like the one it got Jan. 3 from the Eighth U.S. Circuit Court of Appeals, upholding and endorsing the long-embattled Minnesota Sex Offender Program.

The connection is only a mild stretch. This is a moment when Americans and American institutions should be focused on shoring up what might be called constitutional "border security" — vigilantly guarding the boundaries and limits of proper governmental power, especially executive power.

Instead, in the MSOP case, the appeals court has approved an unnervingly sweeping, arbitrary authority, under which government can apparently imprison forever, with few questions asked, anybody it declares dangerous.

It's long been clear that few are much bothered by this kind of unchecked power being brought down upon sex offenders, even after they've served full prison sentences for their crimes. But surely, by now, with Trump's Inauguration Day looming, we should understand the real, underlying reason that limits on government powers must always be enforced, even when we rather like the results of their being exceeded.

We can never be sure who might inherit and wield overgrown government powers next, can we?

At the moment, the main thing we can't be sure of is what to expect from our president-to-be. Of worst-case hysterics, we've maybe had enough. Too many in the political and punditry worlds have, in effect, staked their reputations on Trump's presidency proving both incompetent and iniquitous (and let's hope that if it's wicked it is also ineffective).

But there is reason enough to worry that Trump's nativism, protectionism and alternating isolationism-interventionism could lead to reckless excesses when combined with a brittle, little-boy ego. And when the showoff-in-chief meets institutional obstacles to grandiose plans, as he will, the strength of our constitutional border walls will be tested.

We may wish then that we had more thoroughly followed the advice of a noted American who wrote not long ago: "We should … take every opportunity to affirm the primacy of the Constitution's enduring principles over the politics of the moment. Our failure to do so … will resonate well beyond the particular dispute at hand … in diverse contexts, including those presently unimagined …"

President-elect Trump claims to be an ardent admirer of late Supreme Court Justice Antonin Scalia, who penned those words of warning. Let's hope Trump at least follows through on promises to nominate a replacement for Scalia, and other judges, with similar judicial views.

Nothing so dominated Scalia's thinking as the importance of rigidly following the Constitution as written and originally understood, even when the results are unpopular or inconvenient. Even if one believes that in practice Scalia's devotion to constitutional boundaries was selective or phony, the boundaries themselves whose "primacy" he so often proclaimed are now exactly what America needs.

Scalia, as it happens, though often enough a protector of criminal defendants' rights, signed onto several high court opinions over the years that upheld sex offender commitment procedures somewhat like Minnesota's. But the programs the Supreme Court permitted provided those committed with regular review of their status — or involved a showing of more severe mental abnormality. And Scalia's court emphasized the importance of adequate treatment being provided.

In its ruling this month, the appeals court brushed aside most such niceties. Its decision came in an appeal of an outspoken lower court finding that Minnesota's system for locking up sex offenders long after they've served their time for crimes is unconstitutional — not because the truly dangerous can't be kept behind bars, but because Minnesota's program lacks safeguards allowing at least some to succeed in treatment and win eventual release. Such safeguards exist in many of the 20 other states that have these kinds of systems.

The appeals court basically ruled instead that once the state gets a court to label a person dangerous, that person no longer possesses a "fundamental right" to liberty. The state can lock up such people indefinitely without regular formal review of their continued dangerousness and even without meaningful treatment, and not for punishment of any crime — but simply because doing so is "rationally related" to protecting the public.

Even if one thinks that's good enough for sex offenders, it's possible to imagine such a power being misused. In a terrorism case involving a U.S. citizen during the Bush presidency, Scalia (who could be plenty tough on terror suspects and enemy combatants) wrote: "The very core of liberty secured by our Anglo Saxon system of separated powers has been freedom from indefinite imprisonment at the will of the Executive. … It is unthinkable that the Executive could [justify imprisonment more easily] merely by asserting that it was incapacitating dangerous offenders rather than punishing wrongdoing."

The situations aren't entirely alike, but it's worth noting Scalia's emphasis on our "system of separated powers." What ultimately protects freedom in America from any would-be tyrant are the counterbalancing powers of the various branches and levels of government — but only if courts, Congress, etc., do their duty and protect their turf.

Scalia's warning about his court's failures resonating in "unimagined" contexts came in a 2014 case concerning so-called recess-appointments by President Obama, who suffered a thirst to expand his office's power that all presidents feel.

Scalia was complaining that even though the court had agreed with him in unanimously rejecting Obama's overreach on appointments, the majority was not being sufficiently strict about upholding the limits of presidential authority.

He wrote: "The Constitution's core, government-structuring provisions are no less critical to preserving liberty than ... the Bill of Rights." He saluted "the founding generation's deep conviction that checks and balances were the foundation of a structure of government that would protect liberty" and warned against "aggrandizing the Presidency beyond its constitutional bounds … ."

Obama's admirers, of course, were seldom Scalia's, and have seldom taken such warnings seriously where their hero was concerned. Neither have those who believe we can never be safe enough from crime taken seriously concerns about violating rights.

Let's hope we never learn — at least not anytime soon — how unwise all that may have been.

D.J. Tice is at Doug.Tice@startribune.com.