Integrable Scalar Cosmologies I. Foundations and links with String Theory