Government lawyers wrote a warning letter to Bernard Collaery about the pending publication of his book on Australia’s covert spy operation against Timor-Leste during lucrative oil and gas negotiations.

Two weeks later, a controversial prosecution began against Collaery and Witness K, a former intelligence officer, for their role in shining a light on the bugging of Timor-Leste government buildings.

The ABC on Tuesday revealed that the government sent a warning letter to Collaery about his book. The letter, obtained and published in full by the ABC, was penned by the Australian government solicitor (AGS) in March.

The AGS warned Collaery that it was aware he was planning to publish a book on Witness K and the operation, and advised against making any broader disclosures about the Australian Secret Intelligence Service (Asis) or its staff.

“It is not clear whether, or to what extent, the book may include material relating to the activities of Asis or its staff,” the letter said.

“To avoid any misunderstanding, we are instructed by the director general of Asis to request that you ensure that any such material is properly constrained having regard to the ... Intelligence Services Act 2001.”

It warned breaching the law was punishable by 10 years’ imprisonment.

Court summonses were issued to Collaery and Witness K two weeks later. Collaery and Witness K were charged with criminal offences for earlier disclosures of intelligence secrets. The charges against Collaery relate to earlier discussions with ABC journalists Marian Wilkinson, Peter Lloyd, Conor Duffy, Emma Alberici and producer Peter Cronau.

Collaery declined to comment when contacted on Tuesday. The attorney general, Christian Porter, said the prosecution of Collaery was not informed by “external factors” in any way.

Porter signed off on the prosecution after being presented with commonwealth prosecutors’ assessment of the evidence.

“The decision in this matter was made within months of me taking on the portfolio and was based entirely on the request from the independent CDPP,” Porter said.

“The decision was based on my consideration of the CDPP’s independent assessment of the evidence. External factors played no part in my consideration of the matter.”

The prosecution of Collaery and Witness K has been met with widespread condemnation.

Their actions helped expose a 2004 spy operation designed to give Australia an advantage over its ally during sensitive negotiations to carve up oil and gas reserves in the Timor Sea. After the covert mission was revealed, Timor-Leste took Australia to the permanent court of arbitration in the Hague, challenging the validity of the treaty.

Earlier this year, a new treaty was signed that gave Timor-Leste a fairer deal.

The pair do not consider themselves whistleblowers. Collaery says Witness K, a long-serving Asis operative and patriot, raised concerns about the mission through the proper channels. He was given approval to speak to an approved lawyer, and spoke with Collaery. Collaery represented Timor-Leste in the Hague.

The charges relate to Collaery’s discussions with journalists in 2013, after his home had been raided by police.

The prosecution has been criticised by human rights lawyers, judges, Timor-Leste’s former president José Ramos-Horta, NSW Labor, and the former Victorian premier, Steve Bracks.

Speaking to a rally in Melbourne last month, Bracks said Labor should commit to dropping the prosecution if they win government.

“Why would the Australian government go to the extent of choosing to proceed with a prosecution against Witness K and Bernard Collaery?” he said.

Ramos-Horta told Guardian Australia last month that Australia should drop the case because the two men “acted out of conscience” and “reflected the very best of Australia”.

“This was a very simple case, a political and moral case. So I would hope that Australia would look at it accordingly, proportionally, and let bygones be bygones and let them resume their lives normally,” he said.

The federal opposition has so far been silent on the matter. But the NSW shadow attorney general, Paul Lynch, wants the prosecution dropped.

“You shouldn’t prosecute whistleblowers. It makes it less likely that wrongdoing will be exposed in the future,” Lynch told Guardian Australia earlier this month.

“And you have a sense that they’re really being pursued because of the embarrassment they’ve caused with a rich and powerful nation trying to take advantage of a poor nation.”