California legislative leaders in the wee hours of Wednesday morning reached an agreement with Gov. Gavin Newsom to extend the state’s greenhouse gas emissions reduction program, known as cap and trade, through 2045 — a contentious expansion that for weeks stewed in backroom discussions, held up other critical legislation and roiled insiders.