@staticmethod
def _tagged_contexts(contexts):
    """Reduce the contexts to the latest, and tag them as changed/unchanged since the last save."""
    tagged_contexts = {}
    for tool, current_context in contexts['current_state'].items():
        last_context = contexts['last_saved'].get(tool, None)
        this_tagged_context = current_context.copy()
        changed = last_context != current_context
        this_tagged_context['affected files'] = []
        if last_context and changed and last_context['trigger files'
            ] == this_tagged_context['trigger files'] and last_context['config'
            ] == this_tagged_context['config'] and last_context['preconditions'
            ] == this_tagged_context['preconditions']:
            for file_name, file_hash in list(this_tagged_context[
                'target files'].items()):
                if last_context['target files'].get(file_name, None
                    ) != file_hash:
                    this_tagged_context['affected files'].append(file_name)
        else:
            this_tagged_context['affected files'] = this_tagged_context[
                'target files']
        tagged = {'context': this_tagged_context, 'changed': changed}
        tagged_contexts[tool] = tagged
    return tagged_contexts
