Nearly 20 years after California became the first state to legalize the medical use of marijuana, legislators have a plan to impose order on the erratic patchwork of inconsistent policies that currently govern the billion-dollar industry.

“We’re making up for two decades of inaction”, said state senator Mike McGuire, whose district includes the “Emerald Triangle” in Northern California where 60% of the marijuana grown in the US is cultivated. “This legislation brings clarity and desperately needed rules and regulations.”

In the final hours of the legislative session that ended late Friday night, lawmakers passed a trio of bills that create a legal framework that puts the state firmly in control of managing marijuana from “seed to sale” while still leaving local municipalities with the ability to craft their own ordinances and impose taxes, according to state assembly member Ken Cooley, author of one of the bills. The deal was brokered with the assistance of governor Jerry Brown, virtually ensuring it will be signed into law.

Under the plan, a new Bureau of Medical Marijuana Regulation will be created inside the existing Department of Consumer Affairs, charged with managing almost all aspects of marijuana growing, distribution and sale. The bureau would oversee state licenses in these areas, but only if a local license has already been approved.

“It’s actually innovation in how a state-regulated product gets rolled out in local communities”, said Cooley.

That “local control” element has been a major sticking point for the legislation since discussions began early this year, with law enforcement and city and county governments insistent that they have the ability to regulate the specifics of cannabis commerce within their communities, and some growers initially wary of a plan that was supported by police.

But after “10,000 human hours,” of input from stakeholders, “the current proposals are much different than what we were looking at back then,” says Hezekiah Allen, executive director of the Emerald Growers Association, a trade group of cannabis cultivators with 250 members.

“I couldn’t imagine a better policy package”, he said. “For the first time in generations, we are not going to be criminals … we are on a level playing field with the other stakeholders”.

The bills also cover a large array of other issues, big and small, including tracking mechanisms such as bar coding to follow marijuana from the time it is planted until sold to consumers. They also will allow distributors who have been charged with felonies connected to the sale of marijuana to still qualify for licenses from the state – an issue for many dispensary owners who have operated in grey areas of the law for many years.

On 20 August, California assemblymen, from left, Tom Lackey, Reginald Jones-Sawyer, Rob Bonta, and Ken Cooley pose at the Capitol in Sacramento. Photograph: Rich Pedroncelli/AP

Many of the new measures are meant to address what Cooley called an “environmental crisis” caused by illegal growers, who often dam or divert water from rivers and lakes, dump pesticides and insecticides into public water sources, grade unstable hillsides to create grow sites and leave behind waste when finished.

“This legislation brings forward groundbreaking environmental protection throughout California”, said McGuire.

The laws will make marijuana growers subject to many of the same regulations as any other agricultural crop, with restrictions on water and chemical use. As well, it establishes a grant fund for law enforcement and environmental groups to clean up abandoned grow sites.

It also empowers the California Department of Food and Agriculture to offer an organic label for qualified growers, and establishes “appellation” labeling requirements similar to those found in the wine industry, according to McGuire.

“A grower cannot label their Riverside county-grown cannabis as Humboldt county cannabis”, said McGuire. “We want to be able to protect those family farmers that live and work on the north coast”.

Also to be regulated are the production and sale of edibles, which are a fast-growing segment of the market that current account for about 30 percent of sales but have virtually no health and safety standards. Producers will now be subject to the same type of rules found in other food industries, overseen in part by the state health department.

“Right now if you go into your neighborhood grocery stores, you know that your apples, your oranges, your kiwi, your lettuce, a select sample has been tested prior to hitting the shelves”, said McGuire. “A similar testing will now take place for your medical cannabis”.

Unions may also benefit from the legislation, which includes a component that creates an apprenticeship-training program. Often in California, such programs are union-operated, and some cannabis workers in places including Oakland have already joined unions. The United Food and Commercial Workers and the Teamsters support the legislation.

But medical practitioners who issue licenses will face additional scrutiny. The bill adds “oomph” to the state medical board’s ability to crack down on physicians who issue cannabis prescriptions without a “bonafide basis”, said Cooley. The law may also have a component that creates a state database of prescription holders.

One element that did not make it into the final legislation was a proposed excise tax on finished cannabis products that assemblymember Jim Wood said could have provided $60 million annually to fund law enforcement and environmental cleanup, as well as create a permanent funding source for the watershed enforcement team, a successful multi-agency pilot program that helps legal growers become compliant with environmental rules without legal penalty.

“We just ran out of time to be able to move that particular issue,” he said, adding that he is “committed to introducing that and working on it right away” in the next legislative session.

With multiple ballot initiatives in play in the state to legalize marijuana for recreational use, the issue is almost certain to be put before voters in 2016. Lawmakers said that the new medical marijuana rules would be significant in handling that industry should voters approve such sales.

“A lot of us have had that in the back of our minds,” said Wood. “If legislation does happen, we have some place that we could start.”