Pick up The Great Gamble by Gregory Feifer. It goes into detail on Politburo meetings and Soviet motivations. Yes, the Soviet's "intervention" driven by a desire to prop up the Communist regime because they feared the Afghan Muj would topple the gov't; one way or another, they feared, the Americans would gain a foothold.
Go back to the 50's and 60's, Afghanistan was rather moden, even Westernized in the cities. The West spent hundreds of millions on the country, prompting the Sovs to do the same. We already had good relations with Pakistan and the Sovs viewed us creeping closer to their borders. The notion fo a warm water port is a hundred year old goal turned into a modern myth; those dreams didn't exist in the 21st century.
The Soviets started prepping the ground as early as the spring of 1979. They went with a small SOF footprint that escalated into a massive conventional commitment. Sound familiar?