I liked this idea so much I knocked up a quick and simple implementation of my own, apologies, I hope you don't mind me stealing your idea 😅
I figured it was a lot of work to try to track anything at all, so I reasoned "why don't I just make the separator button simply hide or show anything to the right of it, up to the next detected separator, wherever it happens to be when clicked". This turned out to be really simple to implement.
Whenever a separator is clicked it runs a function that queries every item on the current shelf, iterates over this list, and as soon as it finds "itself" (the clicked button) it starts setting the -manage flag of every subsequent shelfButton to True/False, depending on the "state" of the separator (which I simply use its assigned icon to determine) - until it hits another separator and then it stops the iteration.
I don't bother tracking or storing anything and it seems to work pretty well. The only "downside" is that if the user collapses a load of buttons and THEN drags the collapsed separator elsewhere, it doesn't actually "take" the "collapsed" icons with it. I don't know if you want your implementation to do this, but this seemed like a very minor issue in my opinion, as users wouldn't expect to be able to do that with a regular collapsible layout, and the lack of that functionality isn't really detrimental to the core behaviour or usefulness of the tool.
As a "solution" to the problem of users accidentally leaving icons hidden after moving a separator, I've just added a feature to the trigger function, whereby if the [Alt] key is held, it expands ALL separators on the shelf and shows all unmanaged buttons, so they can "reveal all" easily at any time if they mess up or want to "reset".