Explain how you would solve a task ordering problem that also requires tracking and handling the history of actions. Implement order_tasks(tasks, dependencies, actions), where dependencies are directed [before, after] pairs and actions are ['add', before, after], ['remove', before, after], or ['undo']. Return [ordering, history], using input order to break ties; return an empty ordering if the final dependency graph contains a cycle. History contains the zero-based indices of currently applied add/remove actions in chronological order.
def order_tasks(tasks, dependencies, actions):