HistoryManager
The undo/redo stack. execute runs a Command and makes it undoable; undo/redo walk the history in either direction. canUndo/canRedo are exposed as StateFlow so a host UI can enable/disable undo/redo buttons reactively without polling.
Executing a new command after undoing clears the redo stack — the same behavior as a browser dropping its forward history once you navigate somewhere new after going back. capacity caps how many steps stay undoable; the oldest entry is dropped once exceeded.