Three cheers for sed!
As far as calibre goes, the
editor APIs, which is what I was thinking of, don't do anything to your code.
Conversion is what mangles your code.
You can open up an ebook container, add files as-is (calibre will then take care of managing to OPF), rewrite all your scripts to use python

or use subprocess.check_output() in convoluted ways, build the ToC through XPath, etc.
I'm not saying this is the easiest way for you -- you have to learn python (if you don't know it) first, and migrate a bunch of stuff that
works already, but it is certainly *possible*.
Which is all you asked

: do such scripting tools exist.
Answer: calibre is one such tool, being possessed of extensive python modules for manipulating ebooks.
And just for the perversity: You can turn all that into an editor plugin that can be used from within the ebook-edit GUI.

Then, what is the difference between the GUI and the command line?
Other than processing many books in one pass. (Answer: calibre plugins can have CLI modes. Rarely do their makers create one, but hey, it's possible.

)
You could make a fair argument that the GUI is not just a passing fad.
But then, I could also poke fun at you for using a GUI to write the preceding post, if I was that determined to poke fun at you...
As a fellow believer in flexible automation, can I tempt you with
Vimperator or
VimFX?