Nations working on a global treaty to combat climate change and handle its ill effects have come to a basic draft agreement at conference in Lima, Peru.