IT’S been a pretty grumpy summer in political Scotland, and not just because of the weather. Many SNP activists are still in denial about the independence referendum being indefinitely postponed. Others are bemused by their leader, Nicola Sturgeon, saying she wants to take the “National” out of the SNP, and her agreeing that the GERS hotchpotch of financial statistics confirms that Scotland faces a “challenging deficit”. These are not things that Scottish nationalists like to say in front of the children.

Over on the Labour side, the situation is equally awkward following its UK leader’s uncomfortable tour of Scotland, in which he betrayed an apparent ignorance of Scots law. I suspect that Jeremy Corbyn is dimly aware that Scotland retained its legal system intact after the Union in 1707, but his gaffe at the Edinburgh Festival Fringe confirms his weakness on the constitution. He just doesn’t get it. Mr Corbyn is an old-style socialist who regards this federalism stuff that Kezia Dugdale bangs on about as a bit of a distraction from the class struggle. The Corbyn show wasn’t a wash out, but it was hardly Corbynmania, and merely confirmed that politics is remains very different in Scotland because of the national question. Political leaders here need to be fluent in the language of the constitution to carry conviction.

But as he perambulated around Scotland it suddenly became clear that history has landed the two grumpy parties of Scotland on the same inconvenient side. For all the nastiness on social media and daft claims about Ms Sturgeon being “an austerity conveyor”, the SNP and Labour are for the foreseeable future, condemned to be in agreement about the issues that really matter right now: Brexit and home rule.

While Mr Corbyn was conveniently adrift in the north, his Brexit spokesman in Westminster, Keir Starmer, executed a dramatic U-turn. No longer does Labour insist that the single market is incompatible with Brexit and that British voters must have an end to free movement. “The time for constructive ambiguity is over,” said Mr Starmer, though some might question whether it was either constructive or ambiguous. Three Labour front bench MPs were sacked in June for supporting an SNP-backed amendment calling for the UK to remain in the single market.

Labour is now officially open-minded not just about staying in the single market in a transition period, but about remaining in it indefinitely thereafter. The UK Labour Party has thus tacitly endorsed the arguments in the Scottish Government’s White Paper, Scotland’s Place in Europe, last December that sticking with the single market is “the least worst outcome for the UK as a whole”. Ms Sturgeon should put in a claim for copyright infringement.

But that’s not all. Labour and the SNP are condemned to co-operate also on the Great Repeal Bill and its implications for devolution. When the Labour First Minister of Wales, Carwyn Jones, last month called the EU Withdrawal Bill “a naked power grab by Westminster”, Ms Sturgeon found herself for once upstaged in constitutional hyperbole by a Red Tory. In their meeting in Edinburgh last week, the First Ministers agreed to withhold legislative consent for the Great Repeal Bill. This is emerging as a serious threat to the passage of the Bill.

As even the House of Lords has now recognised, the EU (Withdrawal Bill) represents a “fundamental challenge” to the 1998 Scotland Act, and is technically illegal. The Scotland Act specifies, under Schedule 5, those powers that are reserved by Westminster – defence, foreign affairs, drugsand so on – but famously does not itemise the powers of Holyrood. Where Schedule 5 is silent, the powers of Holyrood begin. This means, as the Lords EU report on devolution last month put it, powers “notably over agriculture, fisheries and the environment will fall automatically to the devolved jurisdictions at the moment of Brexit”. This, to put it mildly, is not how the UK Government sees it.

Clause 11 of the Withdrawal Bill says that only Number 10 will have the power to accept, repeal or amend laws repatriated from Brussels. Only after the UK Prime Minister, using her Henry VIII powers, has decided what’s worth keeping, will powers then be handed, gift-wrapped, to the Scottish Parliament. This is an important constitutional moment, because it reverses the relationship between Holyrood and Westminster. Labour, which was responsible for creating the Scottish Parliament, and the SNP, which now controls it, owe it to the people of Scotland to work closely together to prevent home rule being undermined.

In fact the two issues, single market membership and Scottish home rule are closely related. It is precisely because of the legal standing of the devolved parliament that the Lords argues that Scotland and Wales could, and should, have that “differentiated” relationship” with the EU,that Ms Sturgeon called for. There should be nothing preventing Labour and the SNP working in Westminster and in the devolved parliaments to demand concessions from the UK Government on the single market.

The political leaders of Scotland’s main parties need to get off Twitter, see past their sectarian supporters and realise where the real prize lies. It is not in ideological purity but in compromise and consensus. Ms Sturgeon should look back at those speeches her predecessor made in the Scottish Parliament in May 2007 when he promised to abandon adversarialism and said he would work with the grain of Scottish opinion.

It really doesn’t matter if Labour goes along with this or not, because the Scottish voters can see clearly that the challenges are above party politics. The priority for Scotland right now is to defend the achievements of devolution, and minimise the impact of Brexit. The SNP needs to make itself the leading voice in the opposition to the Great Reform Bill, a position it already holds intellectually thanks to the December White Paper – which was dismissed as unrealistic and fantasy but has now become a key document in the Brexit process.

Nationalists have always tended to regard devolution as, at best, a stepping stone; at worst a Unionist diversion on the way to independence. But it is in their interest to get behind it now because it offers Ms Sturgeon the best way to restore her favour with the Scottish voters, following the abortive second independence referendum episode. Ms Sturgeon made a potentially catastrophic mistake in March when she called a referendum that nobody wanted. But unusually in politics she now has an opportunity to correct that error and restore faith in her Government and in Scottish home rule. Paradoxically, stopping talking about independence is probably the best way to keep it on the political agenda.