Fiddlehead (The Clockwork Century, Book #5) by Cherie Priest
Young ex-slave Gideon Bardsley is a brilliant inventor, but the job is less glamorous than one might think, especially since the assassination attempts started. Worse yet, they're trying to destroy his greatest achievement: a calculating engine called Fiddlehead, which provides undeniable proof of something awful enough to destroy the world. Both man and machine are at risk from forces conspiring to keep the Civil War going and the money flowing.
Bardsley has no choice but to ask his patron, former president Abraham Lincoln, for help. Lincoln retired from leading the country after an attempt on his life, but is quite interested in Bardsley's immense data-processing capacities, confident that if people have the facts, they'll see reason and urge the government to end the war. Lincoln must keep Bardsley safe until he can finish his research, so he calls on his old private security staff to protect Gideon and his data.
Maria "Belle" Boyd was a retired Confederate spy, until she got a life-changing job offer from the Pinkerton Detective Agency. Pinkerton respects her work, despite reservations about her lingering Southern loyalties. But it's precisely those loyalties that let her go into Confederate territory to figure out who might be targeting Bardsley. Maria is a good detective, but with spies from both camps gunning for her, can even the notorious Belle Boyd hold the greedy warhawks at bay?