Start by seeing that the first two terms are the difference of two cubes
a³ – b³ ≡ (a – b)(a² + ab + b²)
Hence
a³ – b³ + 1 + 3ab = (a – b)(a² + ab + b²) + 1 + 3ab
Now add 1 inside the first brackets and subtract 1 times the second brackets to leave the expression unchanged in value
a³ – b³ + 1 + 3ab = (a – b + 1)(a² + ab + b²) –1(a² + ab + b²) + 1 + 3ab
a³ – b³ + 1 + 3ab = (a – b + 1)(a² + ab + b²) – a² – ab – b² + 1 + 3ab
a³ – b³ + 1 + 3ab = (a – b + 1)(a² + ab + b²) – (a² + ab + b² – 1 – 3ab)
a³ – b³ + 1 + 3ab = (a – b + 1)(a² + ab + b²) – (a² + b² – 1 – 2ab)
Recall that (a – b)² ≡ a² – 2ab + b²
a³ – b³ + 1 + 3ab = (a – b + 1)(a² + ab + b²) – ((a – b)² – 1)
Now see the difference of two squares
((a – b)² – 1) = ((a – b)² – 1²) = (a – b + 1)(a – b – 1)
Hence
a³ – b³ + 1 + 3ab = (a – b + 1)(a² + ab + b²) – (a – b + 1)(a – b – 1)
Take out the common factor which is (a – b + 1)
a³ – b³ + 1 + 3ab = (a – b + 1)[(a² + ab + b²) – (a – b – 1)]
Simplify
a³ – b³ + 1 + 3ab = (a – b + 1)(a² + ab + b² – a + b + 1)