U.S. diplomats are reaching the final stages of a negotiation over Taliban obligations not to shelter terrorists if American forces leave Afghanistan, according to Secretary of State Mike Pompeo.

“In light of this progress, we’ve begun discussions with the Taliban regarding foreign military presence, which today remains conditions-based,” Pompeo told reporters during an unannounced trip to Kabul. “And while we’ve made clear to the Taliban that we are prepared to remove our forces, I want to be clear we have not yet agreed on a timeline to do so.”

Pompeo gave that update while emphasizing the need for direct talks between the Taliban and the central government, which the Taliban has refused to begin. His comments were a rare display of optimism for a process that has been complicated by Taliban aggression, the emergence of a dangerous offshoot of the Islamic State, and internal political divisions in Kabul.

“Regarding terrorism, we have made real progress and are nearly ready to conclude a draft text outlining the Taliban’s commitments to join fellow Afghans in ensuring that Afghan soil never again becomes a safe haven for terrorists,” Pompeo said. “All sides agree that finalizing a U.S.-Taliban understanding on terrorism and foreign troop presence will open the door to inter-Afghan dialogue and negotiation.”

That process has been underway since January, when a U.S. negotiating team led by Special Representative Zalmay Khalilzad announced that the Taliban had agreed to a “framework” for an eventual agreement. But the negotiations have been taking place amid a surge of violence by the Taliban and the ISIS affiliate, known as ISIS-Khorasan. The Taliban threatened to launch attacks on Afghan journalists if media outlets do not stop publishing "anti-jihad and Taliban sentiments" by next week.

"In such case, the journalist or employees of these so called media organisations will not be safe," the Taliban said Monday.

On the other hand, U.S. officials have stopped publishing assessments of how much territory the Taliban controls, but civilian deaths reached a record high in 2018 and lawmakers in both parties concede that the group is on the move.

“The Taliban has momentum, but it's still pretty much a stalemate,” said Rhode Island Sen. Jack Reed, the top Democrat on the Armed Services Committee and an ex officio member of the Senate’s intelligence panel, told the Washington Examiner last month after a trip to the country. “They are controlling more territory and picking up some population centers. But, it’s essentially — the government is maintaining control of the population, the bulk of the population.”

Pompeo hoped to have a deal in place before Sept. 1, when Afghan voters are expected to go to the polls for elections that have already been delayed twice. “But the pursuit of peace should not wait until the Afghan presidential election,” he added. "Election planning must go forward without delay as we pursue the peace that Afghans deserve.”

The top American diplomat hopes that an “inter-Afghan dialogue” brokered by Germany and Qatar will help foster an full negotiation between the U.S.-backed government in Kabul and the Taliban.

“That next step is at the heart of our effort,” Pompeo said. We are not and will not negotiate with the Taliban on behalf of the government or people of Afghanistan. Rather, we’re working to bring Afghans together at the negotiating table to decide the future of their own country collectively.”

Pompeo added that the United States expects to maintain a significant presence in Afghanistan even after such a process.

“I had a number of internal meetings today to dig into plans for our future robust diplomatic, security, and development presence,” he said. “The United States will help Afghans preserve the gains of the past 18 years by supporting state civilian governments and their traditions on self-reliance.”