Pakistan should make a deal with US...US can pull out and Pak will go in and occupy the areas in Afghanistan bordering Pak. Take strategic areas like the wakhan corridor to have connectivity with central Asian states. Also take the areas of Afghanistan where the pushtun tribes(that also exist in Pak) live...that way they won't be split between two countries. It would also give Pak some strategic depth. Annex these parts making them part of Pakistan. In the new shrunken Afghanistan...install some puppet government and call it a day.
From the remaining Afghanistan throw a bone to American, Russian, and Chinese companies to mine and whatever else will benefit them...as a way to get the major players on our side and avoid any consequences of invasion/occupation. Use one of the many terrorist attacks that happen from Afghanistan's side as pretext for the invasion. UN will probably condemn these actions but no one would care. It would end the shit show that has gone on in Afghanistan for decades and secure the western border forever. A few decades later the world will forget about it and move on.