Collaborative Undo / Redo behaviour

The inbuilt undo / redo behaviour is unsuitable for a collaborative environment, where remote changes are applied and not expected to be added to the users undo stack (so they can undo their own changes but not those of others).

Is there a way to “intercept” or modify the Undo / Redo stack directly used by CodeMirror so I can synchronize it with my own file diffing logic?

That is exactly how the undo history implemented in @codemirror/commands works.

I understand one can mark transactions as whether or not they are user derived or remote. But the issue is that undo / redo in codeMirror is implemented via just reversing a given transaction.

Even if a line update was made atomatically, it still stores it as absolute document offsets, which may have changed since the original transaction (e.g. another user inserted 10 lines above). So something like that wouldn’t be possible from what I understand, unless there is some way to directly access the undo history buffer / add additional metaData (e.g. line IDs)?

No, it does not, as the existence of the addToHistory annotation demonstrates.