Yeah, I don’t think you’ll find anything that does what you want. Things like twine-utils, Tweego, Extwee don’t look at the contents of the passages (mostly), they just let you put passages for a single story in multiple files and then stuff them all into a single HTML file.
It wouldn’t be too hard to parse the basic Twine link formats ([[passage name]]
, [[link text|passage name]]
etc.) and prefix the passage names somehow, but beyond that…all the story formats have ways to programmatically create links, so in the general case it’s probably not practical.
Both Tweego (written in the Go language) and Extwee (JavaScript) can translate both ways between HTML and Twee-format text files, so if you’re comfortable with one of those languages you could possibly use their source as a starting point?
Or if not, there’s a set of Twine specifications available that describes the Twine HTML format and the Twee text format (as well as how story formats work). So you could just code it from scratch: it’s not that complicated.
Off the top of my head I can’t remember seeing any exceptionally readable code to parse Twine links, though both the Twine editor and any story format would have code for it…