> This almost certainly isn't the first time someone has done whatever it is you are claiming.
I’ve seen category theory papers on this and related topics, but I haven’t seen code in the wild. Have you?
IME this kind of finite state machine business code (as opposed to a FSM embedded in an algorithm somewhere) is written as a one-off each time.
E.g., https://arxiv.org/abs/1808.05415 comes to mind. David I. Spivak has also done some work on composition of systems that is relevant.