TRIPOLI, Libya — As the uprising grew against Moammar Gadhafi, secret reports from his vaunted intelligence service flowed back to Tripoli. Some were mundane — how agents erased anti-regime graffiti. Others were more deadly — a spy volunteered to poison rebel leaders' food and drink.

The reports grew more desperate as the Libyan rebellion veered into civil war: Military leaders in the western mountains were disregarding orders; troops in the city of Misrata ran out of ammunition, turning the situation into "every man for himself."

These reports and hundreds of other intelligence documents seen by The Associated Press in Tripoli trace how the tide shifted in the six-month uprising that ended Gadhafi's 42-year reign. They show how an authoritarian regime using all its means failed to quash an armed rebellion largely fueled by hatred of its tools of control.

The Arab-language documents read and photographed by an AP reporter during a visit to Tripoli's intelligence headquarters contain a mixture of military data and regime propaganda. Amid reports on rebels' movements, phone tap records and dispatches from Gadhafi's domestic agents are memos claiming that al-Qaida was behind the rebellion and that 4,000 U.S. troops were about to invade from Egypt.

The uprising began in mid-February when security forces used deadly fire to suppress anti-government protests in the eastern city of Benghazi. The opposition responded to the fierce crackdown by taking up arms, quickly seizing a large swath of eastern Libya and establishing a temporary administration.

The conflict changed to civil war as rebel forces grew, expelling government forces from of the western city of Misrata and seizing much of the western Nafusa mountain range. It was from there that they pushed to the coast, then stormed into the capital on Aug. 21, effectively ending Gadhafi's rule.

Throughout the war, Gadhafi's security offices in Tripoli directed efforts to quash the rebellion. Among those leading the charge was intelligence chief Abdullah al-Senoussi, whose well-fortified compound received reports from around the country.

Early on, his office struggled to understand the situation in Benghazi, birthplace of the rebels' National Transitional Council.

One of the handwritten intelligence reports, written by a man who said he had "infiltrated" the rebel council, gave the names of five members, their background and the hotels they frequented. None of the material would be unfamiliar to a Benghazi resident.

The note concluded with an offer to kill the council members.

"I can carry out any suicide operation I'm given to assassinate members of the council or poison their food and water," it read.

The author is not identified. No council members have been killed by Gadhafi's regime.

Another report parroted stories spread by Libyan state media that the rebels were linked to Osama bin Laden's al-Qaida terrorist group, that they lacked local support, and that they carried Viagra and condoms into battle so they could rape women.

The regime took these claims to the international community, especially after NATO began bombing Libyan military targets under a U.N. mandate to protect civilians.

One document discovered was a draft letter from Gadhafi to President Barack Obama.

"It is necessary to support Libya to get rid of the armed men of al-Qaida before all of north Africa falls into the hands of bin Laden," it said. It is unclear if the letter was ever sent.

The documents refer to the rebels as "insurgents," ''saboteurs" ''armed gangs" and "rats."

Reports from across Libya detail the government's actions to erase opposition symbols, such as replacing rebel flags with the green banners of the Gadhafi regime or painting over rebel graffiti.

Phone taps were common and sometimes detailed rebel capabilities and movements. One paper cited 30 calls intercepted in one week. Other records contained GPS coordinates of the callers.

The reports also showed how the regime was quick to believe its own disinformation. In one conversation log, an Egyptian man said 4,000 U.S. troops were in Cairo, waiting to enter Libya by land.

"Four thousand, some of them commandos," the Egyptian said. "It's unbelievable."

There were signs of paranoia. In one log, a man with a Gulf Arab accent advised that Gadhafi, his sons and associates "use their cellphone for no more than three minutes," out of fear that they, too, were being intercepted.

In April and May, bleak reports flowed back from the front lines. A report marked "secret" on the situation in the Nafusa mountains laid out a new military strategy while blasting commanders for failing to follow instructions.

"Not paying attention to them in the past did not succeed in ending the actions of armed gangs," it said. "Instead, they have grown stronger (in weapons and numbers)."

Another report detailed information about rebel bases and tactics, but added that government troops were hindered by "their ignorance of the landscape there."

Bad news also came from Misrata, where rebels pushed government troops from the city in late April after weeks of fierce street battles that killed hundreds of people.

A May 5 report depicted chaos in the ranks, saying soldiers often ran out of ammunition before reaching the battlefield, leading many to be killed or captured.

"The rest fled randomly in all directions," the report said, citing the "lack of leaders for members of the armed forces on site (every man for himself)."

Later reports suggested threats inside Tripoli from regime opponents. One envelope contained two handwritten letters, threatening to kill security forces.

"We will take mercy on no one, regardless of his position, and will kill anyone manning a checkpoint," one read. Next to a hand-drawn rebel flag, red ink declared, "You have been warned."

Others suggested a security collapse in the capital as rebel forces moved closer.

One letter from the Investigation and Surveillance Office pleaded with al-Senoussi to intervene at the station, which "has become an office of alcohol, prostitution and theft of property of those arrested."

In the next four pages, the officer accused his boss of getting drunk on the job, stealing money from prisoners and seizing cars to give to his guards, sons and favorite prostitutes.

He said his superior drugged an Egyptian woman and tried to rape her before an aide intervened, and later "sentenced" three of his officers to death.

"This order caused some confusion among those in the office," he noted.

NATO bombed many of Gadhafi's security offices, and rebels stormed the rest after seizing the capital last month.

The International Criminal Court has issued arrest warrants for Gadhafi, his son Seif al-Islam, and al-Senoussi, accusing them of killing civilians to try to crush the uprising. All three remain at large.

A ragged band of mountain rebels now handles security at al-Senoussi's compound, parking their truck under the intelligence services' motto: "The weapons are in the people's hands."

Inside, the fighters lounge in chairs and casually flip through the hundreds of documents strewn on the floor.

Among them is an order from al-Senoussi that wasn't carried out before he fled.

"In the crucial last moments, get rid of the contents of the administration and its secret documents by burning or destroying them," it said.