In 1982, long before most Americans ever had to think about warrantless eavesdropping, the journalist James Bamford published “The Puzzle Palace: A Report on N.S.A., America’s Most Secret Agency,” the first book to be written about the National Security Agency, which was started in 1952 by President Harry Truman to collect intelligence on foreign entities, and which we learned last week has been collecting the phone and Internet records of Americans and others. In the book, Bamford describes the agency as “free of legal restrictions” while wielding “technological capabilities for eavesdropping beyond imagination.” He concludes with an ominous warning: “Like an ever-widening sinkhole, N.S.A.’s surveillance technology will continue to expand, quietly pulling in more and more communications and gradually eliminating more and more privacy.” Three decades later, this pronouncement feels uncomfortably prescient: we were warned.

Bamford, who served in the Navy and studied law before becoming a journalist, published three more books after “The Puzzle Palace,” composing a tetralogy about the N.S.A.: “Body of Secrets: Anatomy of the Ultra-Secret National Security Agency” (2001); “A Pretext for War: 9/11, Iraq, and the Abuse of America’s Intelligence Agencies” (2004); and “The Shadow Factory: The Ultra-Secret N.S.A. from 9/11 to the Eavesdropping on America” (2008). As the progression of subtitles indicates, Bamford has become disenchanted with the agency that he knows probably better than any other outsider. Fellow investigative journalists regard him with what can broadly be described as admiration, though, as the Times reporter Scott Shane wrote, in 2008, “His relationship with the National Security Agency might be compared to a long and rocky romance, in which fascination with his quarry’s size and capabilities has alternated with horror at its power to invade privacy.”

The image of a troubled romance is one that Bamford readily summons. “I have a love-hate relationship with the N.S.A.,” Bamford joked when I spoke to him last week, in the wake of the revelation that the N.S.A. is gathering metadata from telecommunications and Internet companies. “I love them, and they hate me.” They have good reason. Bamford, who divides his time between Washington, D.C., and London, is a slightly mischievous character whose obvious persistence and curiosity have served him well. He talks with the relish of a child who has entered a forbidden room and knows that he will do so again. He decided to write about the N.S.A., which is believed to receive ten billion dollars in annual government funding and employ some forty thousand people, because no one had done it before—and because it was probably more fun than reading case law. While doing research at the Virginia Military Institute, he uncovered a load of N.S.A.-related documents from the files of the masterful Moldovan-born cryptographer William Friedman, as well as those of Marshall Carter, who headed the agency from 1965 to 1969. And, incredibly enough, the Department of Justice, under Jimmy Carter, complied with Bamford’s Freedom of Information Act requests, supplying him with secret documents related to the Church Committee, the Senate group that, in 1975, investigated American intelligence agencies for potential transgression of their mandates.

That the government would hand over sensitive information to Bamford predictably infuriated the N.S.A.; Reagan Administration lawyers tried to bully Bamford into ceding his goods, threatening him with the Espionage Act, while the N.S.A. attempted to sequester the documents he’d uncovered. But because he was a lawyer, Bamford knew that he had done nothing wrong. Unlike the secret court order on wiretapping that required Verizon to supply the N.S.A. with its customers’ phone records which was passed covertly to the Guardian’s Glenn Greenwald, Bamford’s information was obtained through legal channels.

I had a hard time finding “The Puzzle Palace.” Online bookstores notwithstanding, the only physical copy I could locate promptly was at the Queens Central Library. The book was in storage, I was told, and would take some time to retrieve. Indeed, “The Puzzle Palace” has the feel of an artifact, the darkly revealing kind. Though published during the Reagan years, the book is coolly subversive and powerfully prescient. Its warnings of “technotyranny” and reminders that “the same technology that is used against free speech can be used to protect it” sound like something you might hear from a Google executive at a TED talk. Bamford writes with stinging skepticism about the legal procedures created in 1978 under the Foreign Intelligence Surveillance Act to adjudicate spying—the same laws that, since 9/11, have allowed for domestic wiretapping—calling them “a super hush-hush surveillance court that is virtually impotent.”

Bamford’s 1982 book is a reminder to anyone who thinks that domestic eavesdropping is a necessary part of a post-9/11 world that the N.S.A. has tested the bounds of the Fourth Amendment before. Project Shamrock, carried out after the Second World War, compelled companies like Western Union to hand over, on a daily basis, all telegraphs entering and leaving the United States. A younger sibling, Project Minaret, born in 1969, collected information on “individuals or organizations, involved in civil disturbances, antiwar movements/demonstrations and Military deserters involved in the antiwar movement.”

My own favorite passage is of a lighter variety. It describes the N.S.A.’s headquarters, near Washington—sometimes called Crypto City—which Bamford got to visit in exchange for making a few concessions regarding information the N.S.A. was particularly eager to keep out of public view. He writes, “Although security at the Puzzle Palace appears close to hermetic, much of it is little more than illusion. Triple-wrapping in chain link and electricity notwithstanding, access to the front lobby and plush reception area is easier than walking into a Greyhound bus station.” I’m quite certain such laxity is long gone.

If “The Puzzle Palace” is hard to find, it is only because the book that followed, “Body of Secrets,” almost entirely eclipsed it. Published months before 9/11, it is the story of an agency adrift, the Soviet menace diminished but the one from the Middle East not yet in full focus. The book is turgid with agency history, partly because it was the work for which Bamford would receive the most thorough coöperation from the N.S.A. Then director Michael Hayden, who had taken charge of the agency in 1999, even invited Bamford to a dinner at his house. (“He had a three-piece band,” Bamford told me. “Generals get these things.”)

The history is not always kind: “Body of Secrets” opens with a description of American intelligence agents at the end of the Second World War desperate to poach Nazi codebreakers who might have been helpful against the looming Soviet threat. The Suez Crisis of 1956, in which Israel, Britain, and France attacked Egypt, “marked a dismal entry into the world of crisis intelligence,” Bamford writes, the agency’s analysis consisting of nothing more specific or useful than “communications between Paris and Tel Aviv.” Eight years later, the N.S.A. committed a “major blunder,” in Bamford’s words, by inflating the threat of a second attack in the Gulf of Tonkin in the early days of August, 1964, which President Lyndon B. Johnson would use as a pretext for leading the nation into what would become the Vietnam War. Later, Bamford alleges that the N.S.A. lost cryptographic equipment to the North Koreans, who passed it on to the Soviets, who, in turn, handed it over to their North Vietnamese allies (the N.S.A. has disputed this claim). The agency did draw an “electronic noose” around the Soviet Union, though, as Bamford told me later, “because the Cold War remained cold, the N.S.A. was never tested against its ultimate challenge.”