Start refactoring scripts

- Move ScriptContext into script module
- Use mock module instead of hand-rolled mock objects in tests
Clean up and clarify script API
Script refactoring: move script command parsing into script module.