Implement history dir for kernels and refactor magics dir