Introduce `safe` package

Replaces custom functions, e.g. safeTail in Command.hs.
Use foldMapDefault instead of mconcat + comprehension

Instead of using mconcat + comprehension, we can use foldMapDefault from
Data.Traversable, which does exactly this.
Simplify runInState